Commit 1aaa1041 authored by vlad_burin's avatar vlad_burin
Browse files

GUI Qt UClassesListWidget updated.

Added logging and error catching in functions for working with RT libraries.
rdk_system.qt RemoveFile little update

--HG--
branch : RunTimeLibsTest
parent 463bfb020831
......@@ -413,9 +413,6 @@ const std::string& URuntimeLibrary::GetLibPath() const
///
bool URuntimeLibrary::LoadCompDescriptions()
{
// xml
// ClassesStructures
std::vector<std::string> comp_descriptions;
......@@ -441,56 +438,66 @@ bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, const std::
UEPtr<UContainer> p = newclass;
UEPtr<UNet> cont = dynamic_pointer_cast<UNet>(p);
if(!cont)
return false;
std::string buff;
// XML .
// Destroy() , . Create
// Destroy() , . Create
CurrentComponentStruct.Create("stub");
CurrentComponentStruct.Destroy();
// XML RTname
cont->SaveComponent(&CurrentComponentStruct, true, ptPubParameter);
if(!cont->SaveComponent(&CurrentComponentStruct, true, ptPubParameter))
return false;
CurrentComponentStruct.SelectNode(cont->GetName());
CurrentComponentStruct.RenameNode(new_comp_name);
CurrentComponentStruct.SetNodeAttribute("RTname", new_class_name);
CurrentComponentStruct.Save(buff);
//std::string class_name = CurrentComponentStruct.GetNodeAttribute("Class");
//cont=dynamic_pointer_cast<UNet>(Storage->TakeObject(class_name));
CurrentComponentStruct.SaveToFile(LibPath+"/"+new_class_name+".xml");
try
{
UEPtr<UContainer> cont_1 = CreateClassSample(Storage, CurrentComponentStruct);
//
if(UploadClass(new_class_name, cont_1))
ClassesStructures.push_back(buff);
if(!cont_1)
return false;
}
catch(UException &ex)
if(!UploadClass(new_class_name, cont_1))
{
Storage->GetLogger()->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "UploadClass failed while uploading \""+new_class_name + "\" class");
return false;
}
ClassesStructures.push_back(buff);
return true;
}
/// Storage
bool URuntimeLibrary::DelClass(const std::string &class_name)
{
if(class_name.empty())
return false;
// .
if(Storage->CheckClass(class_name))
{
//
if(Storage->FindCollection(class_name).Get()!= dynamic_cast<ULibrary*>(this))
if(Storage->FindCollection(class_name).Get()!= static_cast<ULibrary*>(this))
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "\""+class_name + "\" class exists in another library. Not in \"" + Name +"\"");
return false;
}
//
Storage->DelClass(Storage->FindClassId(class_name));
}
//
for(vector<string>::iterator it = ClassesStructures.begin(); it != ClassesStructures.end(); ++it)
{
CurrentComponentStruct.Load(*it,"");
......@@ -503,6 +510,7 @@ bool URuntimeLibrary::DelClass(const std::string &class_name)
break;
}
}
return true;
}
bool URuntimeLibrary::DeleteOwnDirectory(void)
......@@ -529,6 +537,9 @@ UEPtr<UContainer> URuntimeLibrary::CreateClassSample(UStorage *storage, USerStor
if(!cont->LoadComponent(&xml,true))
{
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Error while LoadComponent() from XML file for class \"" +class_name +"\"");
storage->ReturnObject(cont);
return 0;
}
......@@ -559,7 +570,8 @@ void URuntimeLibrary::CreateClassSamples(UStorage *storage)
}
catch(UException &ex)
{
Storage->GetLogger()->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
if(Storage->GetLogger())
Storage->GetLogger()->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
}
}
}
......
......@@ -889,6 +889,7 @@ const string& UStorage::GetCollectionVersion(int index)
// 'buffer'
void UStorage::GetRTlibsNameList(std::string &buffer) const
{
buffer.clear();
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
......@@ -898,14 +899,15 @@ void UStorage::GetRTlibsNameList(std::string &buffer) const
buffer.append(",");
}
}
buffer.erase(buffer.length()-1);
if(!buffer.empty())
buffer.erase(buffer.length()-1);
}
///
bool UStorage::AddClassToCollection(const std::string &new_class_name, const std::string &new_comp_name, bool force_replace, UContainer *newclass, const std::string &lib_name)
{
try
{
if(new_class_name.empty())
return false;
//
URuntimeLibrary *library = 0;
......@@ -919,6 +921,14 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, const std
}
}
// runtime
if(!library || (library->GetType()!=2))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" +library->GetName() +"\" doesn't exist or it isn't runtime library");
return false;
}
//
if(CheckClass(new_class_name))
{
......@@ -926,13 +936,25 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, const std
if(force_replace)
{
//
URuntimeLibrary *lib = dynamic_cast<URuntimeLibrary*>(FindCollection(new_class_name).Get());
//
lib->DelClass(new_class_name);
//
library->AddNewClass(new_class_name, new_comp_name, newclass);
URuntimeLibrary *lib = static_cast<URuntimeLibrary*>(FindCollection(new_class_name).Get());
if(!lib)
return false;
try
{
//
if(!lib->DelClass(new_class_name))
return false;
}
catch(UException &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
return false;
}
//
// AddNewClass Logger
if(!library->AddNewClass(new_class_name, new_comp_name, newclass))
return false;
}
else
{
......@@ -940,15 +962,9 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, const std
}
}
else
{
library->AddNewClass(new_class_name, new_comp_name, newclass);
}
}
catch(UException &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
{ // AddNewClass Logger
if(!library->AddNewClass(new_class_name, new_comp_name, newclass))
return false;
}
return true;
......@@ -964,11 +980,28 @@ bool UStorage::DelClassFromCollection(const std::string &class_name, const std::
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetName() == lib_name)
{
library = dynamic_cast<URuntimeLibrary*>(lib.Get());
library = static_cast<URuntimeLibrary*>(lib.Get());
}
}
//
library->DelClass(class_name);
// runtime
if(!library || (library->GetType()!=2))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" +library->GetName() +"\" doesn't exist or it isn't runtime library");
return false;
}
//
try
{
if(!library->DelClass(class_name))
return false;
}
catch(UException &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
return false;
}
return true;
}
......@@ -976,10 +1009,18 @@ bool UStorage::DelClassFromCollection(const std::string &class_name, const std::
bool UStorage::CreateRuntimeCollection(const std::string &lib_name)
{
if(lib_name.empty())
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Empty lib name");
return false;
}
if(GetCollection(lib_name) != 0)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library with name \"" + lib_name + "\" already exists");
return false;
}
//
std::string lib_path = "../../../RTlibs/" + lib_name;
......@@ -989,28 +1030,31 @@ bool UStorage::CreateRuntimeCollection(const std::string &lib_name)
if(AddCollection(lib))
{
//
if(RDK::CreateNewDirectory(lib->GetLibPath().c_str())==0)
{
return true;
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "CreateNewDirectory() failed while creating directrory for library \"" + lib_name + "\"");
delete lib;
return false;
}
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "AddCollection() failed while adding the library \"" + lib_name + "\"");
delete lib;
return false;
}
}
/// runtime-
/// runtime-
bool UStorage::DeleteRuntimeCollection(const std::string &lib_name)
{
int index = 0;
int index = -1;
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib=CollectionList[i];
......@@ -1022,19 +1066,43 @@ bool UStorage::DeleteRuntimeCollection(const std::string &lib_name)
}
if(index < 0 || index >= int(CollectionList.size()))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \""+lib_name+"\" not found");
return false;
}
std::vector<ULibrary*>::iterator I=CollectionList.begin()+index;
// runtime-
if((*I)->GetType() == 2)
{
static_cast<URuntimeLibrary*>(*I)->DeleteOwnDirectory();
//
if(!static_cast<URuntimeLibrary*>(*I)->DeleteOwnDirectory())
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" + lib_name + "\" isn't runtime-library");
return false;
}
delete *I;
CollectionList.erase(I);
try
{
// DelClass()
DelAbandonedClasses();
}
catch(UException &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
return false;
}
return true;
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" + lib_name + "\" isn't runtime-library");
return false;
}
}
......@@ -1051,7 +1119,11 @@ void UStorage::InitRTlibs(void)
std::vector<std::string> lib_names;
if(RDK::FindFilesList(lib_path,"*",false,lib_names))
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "FindFilesList() error");
return;
}
for(size_t i = 0 ; i < lib_names.size(); i++)
{
......@@ -1066,9 +1138,13 @@ bool UStorage::LoadRuntimeCollection(const std::string &lib_name)
if(lib_name.empty())
return false;
// ?
//
if(GetCollection(lib_name) != 0)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \""+lib_name+"\" already exists");
return false;
}
//
std::string lib_path = "../../../RTlibs/" + lib_name;
......@@ -1076,8 +1152,13 @@ bool UStorage::LoadRuntimeCollection(const std::string &lib_name)
URuntimeLibrary* lib = new URuntimeLibrary(lib_name,"",lib_path);
//
lib->LoadCompDescriptions();
if(!lib->LoadCompDescriptions())
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "Library \"" + lib_name + "\" error ");
delete lib;
return false;
}
if(AddCollection(lib))
{
......@@ -1085,6 +1166,8 @@ bool UStorage::LoadRuntimeCollection(const std::string &lib_name)
}
else
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, "AddCollection() failed while adding the library \"" + lib_name + "\"");
delete lib;
return false;
}
......
......@@ -322,7 +322,7 @@ virtual bool DelClassFromCollection(const std::string &class_name, const std::st
///
virtual bool CreateRuntimeCollection(const std::string &lib_name);
/// runtime-
/// runtime-
bool DeleteRuntimeCollection(const std::string &lib_name);
// .
......
......@@ -116,8 +116,9 @@ int DeleteDirectory(const char* path)
int RemoveFile(const char* path)
{
QFile file(path);
//
if(!file.exists())
return 1;
return 0;
if(file.remove())
return 0;
......
......@@ -47,7 +47,7 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
{
QListWidgetItem* item = new QListWidgetItem(ui->listWidgetStorageByName);
if(RTclassesNames.indexOf(str)!=-1)
item->setBackgroundColor(Qt::lightGray);
item->setTextColor(Qt::darkCyan);
item->setText(str);
ui->listWidgetStorageByName->addItem(item);
}
......@@ -70,7 +70,7 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
item->setTextColor(0,Qt::darkBlue);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -82,7 +82,7 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
classItem->setTextColor(0,Qt::darkCyan);
}
}
}
......@@ -131,7 +131,6 @@ UClassesListWidget::~UClassesListWidget()
QString UClassesListWidget::selctedClass() const
{
// sigfault
if(ui->listWidgetStorageByName->selectedItems().size() ==0)
return QString();
......@@ -147,24 +146,24 @@ QString UClassesListWidget::selctedClass() const
}
}
void UClassesListWidget::AUpdateInterface(void)
void UClassesListWidget::AUpdateLibsView(QString lib_name)
{
// runtime-
auto storage = RDK::GetStorageLock();
int lib_num = storage->GetNumCollections();
QStringList componentNames;
for (int i = 0; i <lib_num;i++)
{
storage->GetCollection(i);
RDK::UEPtr<RDK::ULibrary> lib = storage->GetCollection(i);
if(lib && lib->GetType() == 2)
{
componentNames.append(QString::fromStdString(lib->GetName()));
}
}
// Storage
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
std::string buff;
storage->GetRTlibsNameList(buff);
QStringList RTlibsNames = QString(buff.c_str()).split(",");
ui->listWidgetRTlibs->clear();
ui->listWidgetRTlibs->addItems(componentNames);
ui->listWidgetRTlibs->addItems(RTlibsNames);
ui->listWidgetRTlibs->sortItems(Qt::AscendingOrder);
auto chosen = ui->listWidgetRTlibs->findItems(lib_name, Qt::MatchExactly);
if(chosen.size()==1)
ui->listWidgetRTlibs->setCurrentItem(chosen.at(0));
}
void UClassesListWidget::SetModelScheme(UDrawEngineImageWidget* model)
......@@ -187,10 +186,11 @@ void UClassesListWidget::dragEvent(QModelIndex index)
drag->exec(Qt::CopyAction, Qt::CopyAction);
}
//
void UClassesListWidget::on_listWidgetRTlibs_itemSelectionChanged()
{
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
if(!item)
return;
QString lib_name = item->text();
//
......@@ -209,6 +209,7 @@ void UClassesListWidget::on_listWidgetRTlibs_itemSelectionChanged()
}
}
//
void UClassesListWidget::tab0_textChanged(const QString &arg1)
{
ui->listWidgetStorageByName->clear();
......@@ -251,7 +252,7 @@ void UClassesListWidget::tab0_textChanged(const QString &arg1)
{
QListWidgetItem* item = new QListWidgetItem(ui->listWidgetStorageByName);
if(RTclassesNames.indexOf(str)!=-1)
item->setBackgroundColor(Qt::lightGray);
item->setTextColor(Qt::darkCyan);
item->setText(str);
ui->listWidgetStorageByName->addItem(item);
}
......@@ -309,7 +310,7 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
item->setTextColor(0,Qt::darkBlue);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -321,7 +322,7 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
classItem->setTextColor(0,Qt::darkCyan);
}
}
......@@ -333,7 +334,7 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
item->setTextColor(0,Qt::darkBlue);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -346,7 +347,7 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
classItem->setTextColor(0,Qt::darkCyan);
}
}
if (!isLibFind)
......@@ -413,19 +414,19 @@ void UClassesListWidget::on_lineEditSearch_textChanged(const QString &arg1)
// Actions
void UClassesListWidget::CreateRTlibrary()
{
// Storage
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
CrLibDialog* dialog = new CrLibDialog;
if(dialog->exec() == QDialog::Accepted)
{
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
std::string lib_name = dialog->GetLibName();
storage->CreateRuntimeCollection(lib_name);
AUpdateInterface();
AUpdateLibsView(QString::fromStdString(lib_name));
}
delete dialog;
}
......@@ -438,7 +439,6 @@ void UClassesListWidget::DeleteRTlibrary()
// Storage
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
......@@ -453,11 +453,9 @@ void UClassesListWidget::DeleteRTlibrary()
if(dialog->exec() == QDialog::Accepted)
{
storage->DeleteRuntimeCollection(lib_name.toLocal8Bit().data());
AUpdateInterface();
AUpdateLibsView("");
}
delete dialog;
......@@ -468,7 +466,7 @@ void UClassesListWidget::AddNewClass()
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
//
if(!engine || !engine->GetModel())
if(!engine || !engine->GetModel() || !engine->GetModel()->GetStorage())
return;
//
......@@ -494,7 +492,7 @@ void UClassesListWidget::AddNewClass()
GetStorage()->AddClassToCollection(dialog->GetClassName(), dialog->GetCompName(),
dialog->GetReplace(), container, dialog->GetLibName());
AUpdateInterface();
AUpdateLibsView(QString::fromStdString(dialog->GetLibName()));
}
delete dialog;
......@@ -528,7 +526,7 @@ void UClassesListWidget::DeleteClass()
{
storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data());
AUpdateInterface();
AUpdateLibsView(lib_name);
}
delete dialog;
}
......@@ -580,7 +578,7 @@ void CrLibDialog::ProcessInput()
//
if(!storage->GetCollection(lib_name))