diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:29 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-10-21 22:48:29 -0400 |
commit | e8a196082586bb68e0bf254a8f6f4b8f39071f32 (patch) | |
tree | b03dbbd1b5be6092ed5e9bcb3806aa2d4938bba3 /src/frontend/bookshelfmanager/removepage | |
parent | dd2f7ce46df53f2c377c02d1bf4df8adcf092072 (diff) |
Imported Upstream version 2.3.3
Diffstat (limited to 'src/frontend/bookshelfmanager/removepage')
-rw-r--r-- | src/frontend/bookshelfmanager/removepage/btremovepage.cpp | 320 | ||||
-rw-r--r-- | src/frontend/bookshelfmanager/removepage/btremovepage.h | 53 |
2 files changed, 182 insertions, 191 deletions
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp index c4324e3..cd8f687 100644 --- a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp +++ b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp @@ -38,192 +38,184 @@ BtRemovePage::BtRemovePage() - : BtConfigPage() -{ - QGridLayout* layout = new QGridLayout(this); - layout->setMargin(5); - - layout->setSpacing(10); - layout->setColumnStretch(1,1); - layout->setRowStretch(2,1); - - m_view = new QTreeWidget(this); - m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path")); - m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20)); - - layout->addWidget( m_view, 2, 0, 1, 2); - - m_removeButton = new QPushButton(tr("Remove..."), this); - m_removeButton->setToolTip(tr("Remove the selected works")); - m_removeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon) ); - m_removeButton->setEnabled(false); - layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight); - - connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int))); - connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveModules())); - connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged())); - populateModuleList(); + : BtConfigPage() { + QGridLayout* layout = new QGridLayout(this); + layout->setMargin(5); + + layout->setSpacing(10); + layout->setColumnStretch(1, 1); + layout->setRowStretch(2, 1); + + m_view = new QTreeWidget(this); + m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path")); + m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20)); + + layout->addWidget( m_view, 2, 0, 1, 2); + + m_removeButton = new QPushButton(tr("Remove..."), this); + m_removeButton->setToolTip(tr("Remove the selected works")); + m_removeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon) ); + m_removeButton->setEnabled(false); + layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight); + + connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int))); + connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveModules())); + connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged())); + populateModuleList(); } -QString BtRemovePage::label() -{ - return tr("Remove installed works. Select the works and click Remove button."); +QString BtRemovePage::label() { + return tr("Remove installed works. Select the works and click Remove button."); } -QString BtRemovePage::iconName() -{ - return CResMgr::bookshelfmgr::removepage::icon; +QString BtRemovePage::iconName() { + return CResMgr::bookshelfmgr::removepage::icon; } -QString BtRemovePage::header() -{ - return tr("Remove"); +QString BtRemovePage::header() { + return tr("Remove"); } -void BtRemovePage::populateModuleList() -{ +void BtRemovePage::populateModuleList() { - m_view->clear(); - m_selectedModules.clear(); + m_view->clear(); + m_selectedModules.clear(); - // disconnect the signal so that we don't have to run functions for every module - disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) ); + // disconnect the signal so that we don't have to run functions for every module + disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) ); - QList<BTModuleTreeItem::Filter*> empty; - BTModuleTreeItem rootItem(empty, (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping)); - addToTree(&rootItem, m_view->invisibleRootItem()); + QList<BTModuleTreeItem::Filter*> empty; + BTModuleTreeItem rootItem(empty, (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping)); + addToTree(&rootItem, m_view->invisibleRootItem()); - // receive signal when user checks modules - connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) ); - qDebug("BtSourceArea::createModuleTree end"); + // receive signal when user checks modules + connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) ); + qDebug("BtSourceArea::createModuleTree end"); } -void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) -{ - //qDebug()<<"BtRemovePage::addToTree "<<item->text(); - //qDebug() << "BTMTItem type: " << item->type(); - - foreach (BTModuleTreeItem* i, item->children()) { - addToTree(i, new QTreeWidgetItem(widgetItem)); - } - if (item->type() != BTModuleTreeItem::Root) { - CSwordModuleInfo* mInfo = item->moduleInfo(); - widgetItem->setText(0, item->text()); - if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) { - //qDebug() << "item"<<item->text()<< "was cat or lang"; - widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate); - } - if (item->type() == BTModuleTreeItem::Module) { - //qDebug() << "item"<<item->text()<< "was a module"; - widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - widgetItem->setCheckState(0, Qt::Unchecked); - - //TODO: add the relevant information in to item or tooltip - // (install path, is still available from some source) - - QString descr(mInfo->config(CSwordModuleInfo::AbsoluteDataPath)); - QString toolTipText = CToolClass::moduleToolTip(mInfo); - widgetItem->setText(1, descr); - widgetItem->setToolTip(0, toolTipText); - widgetItem->setToolTip(1, descr); - } - } +void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) { + //qDebug()<<"BtRemovePage::addToTree "<<item->text(); + //qDebug() << "BTMTItem type: " << item->type(); + + foreach (BTModuleTreeItem* i, item->children()) { + addToTree(i, new QTreeWidgetItem(widgetItem)); + } + if (item->type() != BTModuleTreeItem::Root) { + CSwordModuleInfo* mInfo = item->moduleInfo(); + widgetItem->setText(0, item->text()); + if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) { + //qDebug() << "item"<<item->text()<< "was cat or lang"; + widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate); + } + if (item->type() == BTModuleTreeItem::Module) { + //qDebug() << "item"<<item->text()<< "was a module"; + widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); + widgetItem->setCheckState(0, Qt::Unchecked); + + //TODO: add the relevant information in to item or tooltip + // (install path, is still available from some source) + + QString descr(mInfo->config(CSwordModuleInfo::AbsoluteDataPath)); + QString toolTipText = CToolClass::moduleToolTip(mInfo); + widgetItem->setText(1, descr); + widgetItem->setToolTip(0, toolTipText); + widgetItem->setToolTip(1, descr); + } + } } -void BtRemovePage::slotRemoveModules() -{ - if ( m_selectedModules.empty() ) { - return; //no message, just do nothing - } - - QStringList moduleNames; - foreach (CSwordModuleInfo* m, m_selectedModules) { - moduleNames.append(m->name()); - } - const QString message = tr("You selected the following work(s): ") - .append(moduleNames.join(", ")) - .append("\n\n") - .append(tr("Do you really want to remove them from your system?")); - - if ((QMessageBox::question(this, tr("Remove Works?"), message, QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed. - - // Update the module list before really removing. Remember deleting the pointers later. - QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames); - - sword::InstallMgr installMgr; - QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects - foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) { - Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList - // Find the install path for the sword manager - QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/"; - QString dataPath = mInfo->config(CSwordModuleInfo::DataPath); - if (dataPath.left(2) == "./") { - dataPath = dataPath.mid(2); - } - if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path - prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() ); - } - else { //This is an error, should not happen - qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath; - continue; // don't remove this, go to next of the for loop - } - - // Create the sword manager and remove the module - sword::SWMgr* mgr = mgrDict[ prefixPath ]; - if (!mgr) { //create new mgr if it's not yet available - mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit())); - mgr = mgrDict[ prefixPath ]; - } - qDebug() << "Removing the module"<< mInfo->name() << "..."; - installMgr.removeModule(mgr, mInfo->module()->Name()); - } - //delete the removed moduleinfo pointers - qDeleteAll(toBeDeleted); - //delete all mgrs which were created above - qDeleteAll(mgrDict); - mgrDict.clear(); - } +void BtRemovePage::slotRemoveModules() { + if ( m_selectedModules.empty() ) { + return; //no message, just do nothing + } + + QStringList moduleNames; + foreach (CSwordModuleInfo* m, m_selectedModules) { + moduleNames.append(m->name()); + } + const QString message = tr("You selected the following work(s): ") + .append(moduleNames.join(", ")) + .append("\n\n") + .append(tr("Do you really want to remove them from your system?")); + + if ((QMessageBox::question(this, tr("Remove Works?"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed. + + // Update the module list before really removing. Remember deleting the pointers later. + QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames); + + sword::InstallMgr installMgr; + QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects + foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) { + Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList + // Find the install path for the sword manager + QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/"; + QString dataPath = mInfo->config(CSwordModuleInfo::DataPath); + if (dataPath.left(2) == "./") { + dataPath = dataPath.mid(2); + } + if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path + prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() ); + } + else { //This is an error, should not happen + qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath; + continue; // don't remove this, go to next of the for loop + } + + // Create the sword manager and remove the module + sword::SWMgr* mgr = mgrDict[ prefixPath ]; + if (!mgr) { //create new mgr if it's not yet available + mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit())); + mgr = mgrDict[ prefixPath ]; + } + qDebug() << "Removing the module" << mInfo->name() << "..."; + installMgr.removeModule(mgr, mInfo->module()->Name()); + } + //delete the removed moduleinfo pointers + qDeleteAll(toBeDeleted); + //delete all mgrs which were created above + qDeleteAll(mgrDict); + mgrDict.clear(); + } } -void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column) -{ - //qDebug("BtRemovePage::slotSelectionChanged"); - // modify the internal list of checked modules - // if() leaves groups away - if (!item->childCount() && column == 0) { - CSwordModuleInfo* mInfo = 0; - //qDebug("BtRemovePage::slotSelectionChanged"); - foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) { - if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) { - mInfo = module; - break; - } - } - Q_ASSERT(mInfo); // this should have been found - if (item->checkState(0) == Qt::Checked) { - //qDebug() << item->text(0) << "in" << item->text(1) << "was checked"; - m_selectedModules.append(mInfo); - } else { - //qDebug() << mInfo->name() << "was unchecked"; - m_selectedModules.removeAll(mInfo); // there is only one, it's a pointer - } - - if (m_selectedModules.count() > 0) { - m_removeButton->setEnabled(true); - } else { - m_removeButton->setEnabled(false); - } - } +void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column) { + //qDebug("BtRemovePage::slotSelectionChanged"); + // modify the internal list of checked modules + // if() leaves groups away + if (!item->childCount() && column == 0) { + CSwordModuleInfo* mInfo = 0; + //qDebug("BtRemovePage::slotSelectionChanged"); + foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) { + if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) { + mInfo = module; + break; + } + } + Q_ASSERT(mInfo); // this should have been found + if (item->checkState(0) == Qt::Checked) { + //qDebug() << item->text(0) << "in" << item->text(1) << "was checked"; + m_selectedModules.append(mInfo); + } + else { + //qDebug() << mInfo->name() << "was unchecked"; + m_selectedModules.removeAll(mInfo); // there is only one, it's a pointer + } + + if (m_selectedModules.count() > 0) { + m_removeButton->setEnabled(true); + } + else { + m_removeButton->setEnabled(false); + } + } } -void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/) -{ - // TODO: Open the About dialog. +void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/) { + // TODO: Open the About dialog. } -void BtRemovePage::slotSwordSetupChanged() -{ - populateModuleList(); +void BtRemovePage::slotSwordSetupChanged() { + populateModuleList(); } diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.h b/src/frontend/bookshelfmanager/removepage/btremovepage.h index 046534c..782fcc0 100644 --- a/src/frontend/bookshelfmanager/removepage/btremovepage.h +++ b/src/frontend/bookshelfmanager/removepage/btremovepage.h @@ -24,44 +24,43 @@ class QTreeWidgetItem; class QPushButton; -class BtRemovePage : public BtConfigPage -{ - Q_OBJECT +class BtRemovePage : public BtConfigPage { + Q_OBJECT -public: - BtRemovePage(); + public: + BtRemovePage(); - ~BtRemovePage(){} + ~BtRemovePage() {} - // BtConfigPage methods - QString header(); - QString iconName(); - QString label(); + // BtConfigPage methods + QString header(); + QString iconName(); + QString label(); - void populateModuleList(); + void populateModuleList(); //signals: - //void swordSetupChanged(); + //void swordSetupChanged(); -public slots: - void slotSwordSetupChanged(); + public slots: + void slotSwordSetupChanged(); -private slots: + private slots: - void slotRemoveModules(); - /** Handles activating the Remove button. */ - void slotSelectionChanged(QTreeWidgetItem* item, int column); - void slotItemDoubleClicked(QTreeWidgetItem* item, int column); + void slotRemoveModules(); + /** Handles activating the Remove button. */ + void slotSelectionChanged(QTreeWidgetItem* item, int column); + void slotItemDoubleClicked(QTreeWidgetItem* item, int column); -private: // methods - void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem); + private: // methods + void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem); + + private: // data + QTreeWidget* m_view; + QPushButton* m_removeButton; + /** Map of module name and install path (absolute path from the moduleinfo config entry).*/ + QList<CSwordModuleInfo*> m_selectedModules; -private: // data - QTreeWidget* m_view; - QPushButton* m_removeButton; - /** Map of module name and install path (absolute path from the moduleinfo config entry).*/ - QList<CSwordModuleInfo*> m_selectedModules; - }; #endif |