summaryrefslogtreecommitdiff
path: root/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/bookshelfmanager/removepage/btremovepage.cpp')
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.cpp143
1 files changed, 97 insertions, 46 deletions
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
index 3f602e0..a19ab89 100644
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
@@ -4,7 +4,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2009 by the BibleTime developers.
+* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
@@ -12,90 +12,137 @@
#include "frontend/bookshelfmanager/removepage/btremovepage.h"
-#include <QGridLayout>
+#include <QAction>
+#include <QGroupBox>
+#include <QHBoxLayout>
#include <QHeaderView>
-#include <QList>
+#include <QMessageBox>
#include <QPushButton>
-#include <QTreeView>
-#include "backend/drivers/cswordmoduleinfo.h"
+#include <QToolButton>
+#include <QVBoxLayout>
+#include "backend/bookshelfmodel/btbookshelffiltermodel.h"
#include "backend/managers/cswordbackend.h"
-#include "util/directory.h"
-#include "util/dialogutil.h"
-#include "util/cpointers.h"
+#include "frontend/btbookshelfview.h"
+#include "frontend/btbookshelfwidget.h"
#include "util/cresmgr.h"
+#include "util/dialogutil.h"
+#include "util/directory.h"
// Sword includes:
#include <swmgr.h>
#include <installmgr.h>
-BtRemovePage::BtRemovePage()
- : BtConfigPage() {
- namespace DU = util::directory;
-
- QGridLayout* layout = new QGridLayout(this);
- layout->setMargin(5);
-
- layout->setSpacing(10);
- layout->setColumnStretch(1, 1);
- layout->setRowStretch(2, 1);
-
- m_model = new BtRemovePageTreeModel(this);
- m_model->setSourceModel(CPointers::backend()->model());
-
- m_view = new QTreeView(this);
- m_view->header()->setResizeMode(QHeaderView::ResizeToContents);
- m_view->setModel(m_model);
+namespace {
+const QString groupingOrderKey("GUI/BookshelfManager/RemovePage/grouping");
+}
- layout->addWidget(m_view, 2, 0, 1, 2);
+BtRemovePage::BtRemovePage(QWidget *parent)
+ : BtConfigPage(parent)
+{
+ namespace DU = util::directory;
- m_removeButton = new QPushButton(tr("Remove..."), this);
+ m_worksGroupBox = new QGroupBox(tr("Select &works to uninstall:"), this);
+ m_worksGroupBox->setFlat(true);
+ QVBoxLayout *wLayout = new QVBoxLayout;
+ wLayout->setContentsMargins(0, 0, 0, 0);
+ m_worksGroupBox->setLayout(wLayout);
+
+ BtRemovePageTreeModel *treeModel = new BtRemovePageTreeModel(groupingOrderKey,
+ this);
+ connect(treeModel, SIGNAL(groupingOrderChanged(BtBookshelfTreeModel::Grouping)),
+ this, SLOT(slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping&)));
+
+ m_bookshelfWidget = new BtBookshelfWidget(this);
+ m_bookshelfWidget->postFilterModel()->setShowHidden(true);
+ m_bookshelfWidget->setTreeModel(treeModel);
+ m_bookshelfWidget->setSourceModel(CSwordBackend::instance()->model());
+ m_bookshelfWidget->showHideAction()->setVisible(false);
+ m_bookshelfWidget->showHideButton()->hide();
+ m_bookshelfWidget->treeView()->header()->show();
+ m_bookshelfWidget->treeView()->header()->setResizeMode(QHeaderView::ResizeToContents);
+ wLayout->addWidget(m_bookshelfWidget);
+
+ m_uninstallGroupBox = new QGroupBox(this);
+ m_uninstallGroupBox->setFlat(true);
+ retranslateUninstallGroupBox();
+ QHBoxLayout *uLayout = new QHBoxLayout;
+ uLayout->setContentsMargins(0, 0, 0, 0);
+ m_uninstallGroupBox->setLayout(uLayout);
+ uLayout->addStretch(1);
+
+ m_removeButton = new QPushButton(tr("&Remove..."), this);
m_removeButton->setToolTip(tr("Remove the selected works"));
m_removeButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon));
m_removeButton->setEnabled(false);
- layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight);
+ uLayout->addWidget(m_removeButton, 0, Qt::AlignRight);
+
+ Q_ASSERT(qobject_cast<QVBoxLayout*>(layout()) != 0);
+ QVBoxLayout *mainLayout = static_cast<QVBoxLayout*>(layout());
+ mainLayout->addWidget(m_worksGroupBox, 1);
+ mainLayout->addWidget(m_uninstallGroupBox);
connect(m_removeButton, SIGNAL(clicked()),
this, SLOT(slotRemoveModules()));
- connect(m_model, SIGNAL(moduleChecked(CSwordModuleInfo*, bool)),
- this, SLOT(resetRemoveButton()));
- connect(m_model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
- this, SLOT(resetRemoveButton()));
+ connect(m_bookshelfWidget->treeModel(), SIGNAL(moduleChecked(CSwordModuleInfo*,bool)),
+ this, SLOT(slotResetRemoveButton()));
+ connect(m_bookshelfWidget->treeModel(), SIGNAL(rowsRemoved(const QModelIndex&,int,int)),
+ this, SLOT(slotResetRemoveButton()));
}
-QString BtRemovePage::label() {
- return tr("Remove installed works. Select the works and click Remove button.");
+const QIcon &BtRemovePage::icon() const {
+ return util::directory::getIcon(CResMgr::bookshelfmgr::removepage::icon);
}
-QString BtRemovePage::iconName() {
- return CResMgr::bookshelfmgr::removepage::icon;
+QString BtRemovePage::header() const {
+ return tr("Remove");
}
-QString BtRemovePage::header() {
- return tr("Remove");
+void BtRemovePage::retranslateUninstallGroupBox() {
+ int count = m_bookshelfWidget->treeModel()->checkedModules().count();
+ if (count > 0) {
+ m_uninstallGroupBox->setTitle(tr("Start removal of %1 works:")
+ .arg(count));
+ } else {
+ m_uninstallGroupBox->setTitle(tr("Start removal:"));
+ }
}
-void BtRemovePage::resetRemoveButton() {
- m_removeButton->setEnabled(!m_model->checkedModules().empty());
+void BtRemovePage::slotResetRemoveButton() {
+ retranslateUninstallGroupBox();
+ m_removeButton->setEnabled(!m_bookshelfWidget->treeModel()->checkedModules().empty());
}
void BtRemovePage::slotRemoveModules() {
// Do nothing when this signal fires without anything selected to remove:
- if (m_model->checkedModules().empty()) return;
+ if (m_bookshelfWidget->treeModel()->checkedModules().empty()) return;
QStringList moduleNames;
- foreach (CSwordModuleInfo *m, m_model->checkedModules()) {
- moduleNames.append(m->name());
+ const int textHeight = fontMetrics().height();
+ /// \bug <nobr> is not working, Qt bug
+ const QString moduleString("<nobr><img src=\"%1\" width=\"%2\" height=\"%3\"/>&nbsp;%4</nobr>");
+ const QString iconDir = util::directory::getIconDir().canonicalPath() + '/';
+ Q_FOREACH(const CSwordModuleInfo *m,
+ m_bookshelfWidget->treeModel()->checkedModules())
+ {
+ const QIcon icon = CSwordModuleInfo::moduleIcon(m);
+ const QSize iconSize = icon.actualSize(QSize(textHeight, textHeight));
+ moduleNames.append(moduleString
+ .arg(iconDir + CSwordModuleInfo::moduleIconFilename(m))
+ .arg(iconSize.width())
+ .arg(iconSize.height())
+ .arg(m->name()));
}
const QString message = tr("You selected the following work(s): ")
- .append(moduleNames.join(", "))
- .append("\n\n")
+ .append("<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;")
+ .append(moduleNames.join(",&nbsp; "))
+ .append("<br/><br/>")
.append(tr("Do you really want to remove them from your system?"));
if ((util::showQuestion(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);
+ QList<CSwordModuleInfo*> toBeDeleted = CSwordBackend::instance()->takeModulesFromList(moduleNames);
sword::InstallMgr installMgr;
QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects
@@ -131,3 +178,7 @@ void BtRemovePage::slotRemoveModules() {
mgrDict.clear();
}
}
+
+void BtRemovePage::slotGroupingOrderChanged(const BtBookshelfTreeModel::Grouping &g) {
+ g.saveTo(groupingOrderKey);
+}