Cleaned service menu, now service menus use context menus only.

This commit is contained in:
Martin Rotter 2015-11-25 08:36:58 +01:00
parent 85a7f104cf
commit 8ae9c97248
16 changed files with 56 additions and 71 deletions

View File

@ -339,17 +339,31 @@ void FeedsModel::reloadCountsOfWholeModel() {
void FeedsModel::removeItem(const QModelIndex &index) { void FeedsModel::removeItem(const QModelIndex &index) {
if (index.isValid()) { if (index.isValid()) {
QModelIndex parent_index = index.parent();
RootItem *deleting_item = itemForIndex(index); RootItem *deleting_item = itemForIndex(index);
QModelIndex parent_index = index.parent();
RootItem *parent_item = deleting_item->parent(); RootItem *parent_item = deleting_item->parent();
// Item was persistently removed.
// Remove it from the model.
beginRemoveRows(parent_index, index.row(), index.row()); beginRemoveRows(parent_index, index.row(), index.row());
parent_item->removeChild(deleting_item); parent_item->removeChild(deleting_item);
endRemoveRows(); endRemoveRows();
delete deleting_item; deleting_item->deleteLater();
notifyWithCounts();
}
}
void FeedsModel::removeItem(RootItem *deleting_item) {
if (deleting_item != NULL) {
QModelIndex index = indexForItem(deleting_item);
QModelIndex parent_index = index.parent();
RootItem *parent_item = deleting_item->parent();
beginRemoveRows(parent_index, index.row(), index.row());
parent_item->removeChild(deleting_item);
endRemoveRows();
deleting_item->deleteLater();
notifyWithCounts();
} }
} }

View File

@ -67,6 +67,7 @@ class FeedsModel : public QAbstractItemModel {
// Removes item with given index. // Removes item with given index.
// NOTE: Also deletes item from memory. // NOTE: Also deletes item from memory.
void removeItem(const QModelIndex &index); void removeItem(const QModelIndex &index);
void removeItem(RootItem *deleting_item);
// Checks if new parent node is different from one used by original node. // Checks if new parent node is different from one used by original node.
// If it is, then it reassigns original_node to new parent. // If it is, then it reassigns original_node to new parent.

View File

@ -71,7 +71,7 @@ void DynamicShortcutsWidget::populate(QList<QAction*> actions) {
int row_id = 0; int row_id = 0;
// TODO: Maybe separate actions into "categories". Each category will start with label. // FIXME: Maybe separate actions into "categories". Each category will start with label.
// I will assign each QAaction a property called "category" with some enum value. // I will assign each QAaction a property called "category" with some enum value.
// Like: // Like:
// File, FeedsCategories, Messages, Tools, WebBrowser, Help // File, FeedsCategories, Messages, Tools, WebBrowser, Help

View File

@ -129,6 +129,7 @@ QList<QAction*> FormMain::allActions() {
actions << m_ui->m_actionUpdateSelectedItems; actions << m_ui->m_actionUpdateSelectedItems;
actions << m_ui->m_actionEditSelectedItem; actions << m_ui->m_actionEditSelectedItem;
actions << m_ui->m_actionDeleteSelectedItem; actions << m_ui->m_actionDeleteSelectedItem;
actions << m_ui->m_actionServiceAdd;
actions << m_ui->m_actionViewSelectedItemsNewspaperMode; actions << m_ui->m_actionViewSelectedItemsNewspaperMode;
actions << m_ui->m_actionSelectNextItem; actions << m_ui->m_actionSelectNextItem;
actions << m_ui->m_actionSelectPreviousItem; actions << m_ui->m_actionSelectPreviousItem;
@ -197,12 +198,15 @@ void FormMain::updateAddItemMenu() {
m_ui->m_menuAddItem->addMenu(root_menu); m_ui->m_menuAddItem->addMenu(root_menu);
} }
}
void FormMain::updateServicesMenu() { if (m_ui->m_menuAddItem->actions().size() > 0) {
m_ui->m_menuServices->clear(); m_ui->m_menuAddItem->addSeparator();
}
foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) { m_ui->m_menuAddItem->addAction(m_ui->m_actionServiceAdd);
/*
* foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) {
QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuServices); QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuServices);
root_menu->setIcon(activated_root->icon()); root_menu->setIcon(activated_root->icon());
root_menu->setToolTip(activated_root->description()); root_menu->setToolTip(activated_root->description());
@ -221,22 +225,14 @@ void FormMain::updateServicesMenu() {
} }
m_ui->m_menuServices->addMenu(root_menu); m_ui->m_menuServices->addMenu(root_menu);
} }*/
if (!m_ui->m_menuServices->isEmpty()) {
m_ui->m_menuServices->addSeparator();
}
m_ui->m_menuServices->addAction(m_ui->m_actionServiceAdd);
m_ui->m_menuServices->addAction(m_ui->m_actionServiceEdit);
m_ui->m_menuServices->addAction(m_ui->m_actionServiceDelete);
} }
void FormMain::updateRecycleBinMenu() { void FormMain::updateRecycleBinMenu() {
m_ui->m_menuRecycleBin->clear(); m_ui->m_menuRecycleBin->clear();
foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) { foreach (ServiceRoot *activated_root, tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->serviceRoots()) {
QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuServices); QMenu *root_menu = new QMenu(activated_root->title(), m_ui->m_menuRecycleBin);
root_menu->setIcon(activated_root->icon()); root_menu->setIcon(activated_root->icon());
root_menu->setToolTip(activated_root->description()); root_menu->setToolTip(activated_root->description());
@ -442,7 +438,6 @@ void FormMain::createConnections() {
connect(m_ui->m_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool))); connect(m_ui->m_actionFullscreen, SIGNAL(toggled(bool)), m_statusBar->fullscreenSwitcher(), SLOT(setChecked(bool)));
connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu())); connect(m_ui->m_menuAddItem, SIGNAL(aboutToShow()), this, SLOT(updateAddItemMenu()));
connect(m_ui->m_menuServices, SIGNAL(aboutToShow()), this, SLOT(updateServicesMenu()));
connect(m_ui->m_menuRecycleBin, SIGNAL(aboutToShow()), this, SLOT(updateRecycleBinMenu())); connect(m_ui->m_menuRecycleBin, SIGNAL(aboutToShow()), this, SLOT(updateRecycleBinMenu()));
// Menu "File" connections. // Menu "File" connections.

View File

@ -78,7 +78,6 @@ class FormMain : public QMainWindow {
private slots: private slots:
void updateAddItemMenu(); void updateAddItemMenu();
void updateServicesMenu();
void updateRecycleBinMenu(); void updateRecycleBinMenu();
// Loads web browser menu if user selects to change tabs. // Loads web browser menu if user selects to change tabs.

View File

@ -131,6 +131,7 @@
<property name="title"> <property name="title">
<string>Add &amp;new item</string> <string>Add &amp;new item</string>
</property> </property>
<addaction name="m_actionServiceAdd"/>
</widget> </widget>
<addaction name="m_actionUpdateAllItems"/> <addaction name="m_actionUpdateAllItems"/>
<addaction name="m_actionUpdateSelectedItems"/> <addaction name="m_actionUpdateSelectedItems"/>
@ -171,14 +172,6 @@
<addaction name="m_actionDeleteSelectedMessages"/> <addaction name="m_actionDeleteSelectedMessages"/>
<addaction name="m_actionRestoreSelectedMessages"/> <addaction name="m_actionRestoreSelectedMessages"/>
</widget> </widget>
<widget class="QMenu" name="m_menuServices">
<property name="title">
<string>&amp;Services</string>
</property>
<addaction name="m_actionServiceAdd"/>
<addaction name="m_actionServiceEdit"/>
<addaction name="m_actionServiceDelete"/>
</widget>
<widget class="QMenu" name="m_menuRecycleBin"> <widget class="QMenu" name="m_menuRecycleBin">
<property name="title"> <property name="title">
<string>&amp;Recycle bin</string> <string>&amp;Recycle bin</string>
@ -188,7 +181,6 @@
</widget> </widget>
<addaction name="m_menuFile"/> <addaction name="m_menuFile"/>
<addaction name="m_menuView"/> <addaction name="m_menuView"/>
<addaction name="m_menuServices"/>
<addaction name="m_menuFeeds"/> <addaction name="m_menuFeeds"/>
<addaction name="m_menuMessages"/> <addaction name="m_menuMessages"/>
<addaction name="m_menuRecycleBin"/> <addaction name="m_menuRecycleBin"/>
@ -717,28 +709,6 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
</action> </action>
<action name="m_actionServiceDelete">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Delete selected service account</string>
</property>
<property name="shortcut">
<string notr="true"/>
</property>
</action>
<action name="m_actionServiceEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Edit selected service account</string>
</property>
<property name="shortcut">
<string notr="true"/>
</property>
</action>
<action name="m_actionRestoreSelectedMessages"> <action name="m_actionRestoreSelectedMessages">
<property name="text"> <property name="text">
<string>&amp;Restore selected messages</string> <string>&amp;Restore selected messages</string>

View File

@ -202,8 +202,6 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
bool service_selected = anything_selected && selected_item->kind() == RootItemKind::ServiceRoot; bool service_selected = anything_selected && selected_item->kind() == RootItemKind::ServiceRoot;
FormMain *form_main = qApp->mainForm(); FormMain *form_main = qApp->mainForm();
form_main->m_ui->m_actionServiceEdit->setEnabled(!critical_action_running && service_selected);
form_main->m_ui->m_actionServiceDelete->setEnabled(!critical_action_running && service_selected);
form_main->m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running); form_main->m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running);
form_main->m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running); form_main->m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running);
form_main->m_ui->m_actionClearSelectedItems->setEnabled(feed_selected || category_selected || service_selected); form_main->m_ui->m_actionClearSelectedItems->setEnabled(feed_selected || category_selected || service_selected);

View File

@ -239,15 +239,6 @@ void FeedsView::deleteSelectedItem() {
qApp->mainForm(), qApp->mainForm(),
true); true);
} }
else {
// Item is gone, cleared from database. We can clear it from model now.
// NOTE: Cleared from memory here too.
// TODO: možná toto přesunout taky to metody deleteViaGui
// a delete selected_item jen volat tady, editViaGui taky obstará všechno,
// ale tam je to zas komplexnější.
m_sourceModel->removeItem(m_proxyModel->mapToSource(current_index));
m_sourceModel->notifyWithCounts();
}
} }
else { else {
qApp->showGuiMessage(tr("Cannot delete \"%1\"").arg(selected_item->title()), qApp->showGuiMessage(tr("Cannot delete \"%1\"").arg(selected_item->title()),

View File

@ -124,7 +124,7 @@ void SystemTrayIcon::setNumber(int number, bool any_new_message) {
QPixmap background(m_plainPixmap); QPixmap background(m_plainPixmap);
QPainter tray_painter; QPainter tray_painter;
// TODO: Here draw different background instead of different color of number. // FIXME: Here draw different background instead of different color of number.
tray_painter.begin(&background); tray_painter.begin(&background);
tray_painter.setPen(any_new_message ? Qt::blue : Qt::black); tray_painter.setPen(any_new_message ? Qt::blue : Qt::black);
tray_painter.setRenderHint(QPainter::SmoothPixmapTransform, true); tray_painter.setRenderHint(QPainter::SmoothPixmapTransform, true);

View File

@ -69,7 +69,6 @@ void TabWidget::openMainMenu() {
m_menuMain = new QMenu(tr("Main menu"), this); m_menuMain = new QMenu(tr("Main menu"), this);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuFile); m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuFile);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuView); m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuView);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuServices);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuFeeds); m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuFeeds);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuMessages); m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuMessages);
m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuWebBrowser); m_menuMain->addMenu(qApp->mainForm()->m_ui->m_menuWebBrowser);

View File

@ -39,7 +39,7 @@ WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() {
void WebBrowserNetworkAccessManager::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) { void WebBrowserNetworkAccessManager::onAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) {
Q_UNUSED(authenticator); Q_UNUSED(authenticator);
// TODO: Support authentication for web pages. // FIXME: Support authentication for web pages.
qDebug("URL '%s' requested authentication but username/password is not available.", qPrintable(reply->url().toString())); qDebug("URL '%s' requested authentication but username/password is not available.", qPrintable(reply->url().toString()));
} }

View File

@ -53,6 +53,7 @@ class ServiceRoot : public RootItem {
// NOTE: Caller does NOT take ownership of created menu! // NOTE: Caller does NOT take ownership of created menu!
virtual QList<QAction*> serviceMenu() = 0; virtual QList<QAction*> serviceMenu() = 0;
// Access to recycle bin of this account if there is any.
virtual RecycleBin *recycleBin() = 0; virtual RecycleBin *recycleBin() = 0;
// Start/stop services. // Start/stop services.

View File

@ -99,7 +99,13 @@ bool StandardCategory::editViaGui() {
} }
bool StandardCategory::deleteViaGui() { bool StandardCategory::deleteViaGui() {
return removeItself(); if (removeItself()) {
serviceRoot()->feedsModel()->removeItem(this);
return true;
}
else {
return false;
}
} }
bool StandardCategory::markAsReadUnread(ReadStatus status) { bool StandardCategory::markAsReadUnread(ReadStatus status) {
@ -113,7 +119,8 @@ bool StandardCategory::cleanMessages(bool clean_read_only) {
bool StandardCategory::removeItself() { bool StandardCategory::removeItself() {
bool children_removed = true; bool children_removed = true;
// Remove all child items (feeds, categories.) // Remove all child items (feeds and categories)
// from the database.
foreach (RootItem *child, childItems()) { foreach (RootItem *child, childItems()) {
if (child->kind() == RootItemKind::Category) { if (child->kind() == RootItemKind::Category) {
children_removed &= static_cast<StandardCategory*>(child)->removeItself(); children_removed &= static_cast<StandardCategory*>(child)->removeItself();

View File

@ -115,7 +115,13 @@ bool StandardFeed::editViaGui() {
} }
bool StandardFeed::deleteViaGui() { bool StandardFeed::deleteViaGui() {
return removeItself(); if (removeItself()) {
serviceRoot()->feedsModel()->removeItem(this);
return true;
}
else {
return false;
}
} }
bool StandardFeed::markAsReadUnread(ReadStatus status) { bool StandardFeed::markAsReadUnread(ReadStatus status) {

View File

@ -88,8 +88,6 @@ void StandardServiceRoot::start() {
try { try {
model.importAsOPML20(IOFactory::readTextFile(file_to_load)); model.importAsOPML20(IOFactory::readTextFile(file_to_load));
model.checkAllItems(); model.checkAllItems();
// TODO: Expand all items here?
mergeImportExportModel(&model, output_msg); mergeImportExportModel(&model, output_msg);
} }
catch (ApplicationException &ex) { catch (ApplicationException &ex) {
@ -593,6 +591,10 @@ QList<QAction*> StandardServiceRoot::serviceMenu() {
return m_serviceMenu; return m_serviceMenu;
} }
QList<QAction*> StandardServiceRoot::contextMenuActions() {
return serviceMenu();
}
bool StandardServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) { bool StandardServiceRoot::loadMessagesForItem(RootItem *item, QSqlTableModel *model) {
if (item->kind() == RootItemKind::Bin) { if (item->kind() == RootItemKind::Bin) {
model->setFilter(QSL("is_deleted = 1 AND is_pdeleted = 0")); model->setFilter(QSL("is_deleted = 1 AND is_pdeleted = 0"));

View File

@ -59,6 +59,8 @@ class StandardServiceRoot : public ServiceRoot {
// Return menu to be shown in "Services -> service" menu. // Return menu to be shown in "Services -> service" menu.
QList<QAction*> serviceMenu(); QList<QAction*> serviceMenu();
QList<QAction*> contextMenuActions();
// Message stuff. // Message stuff.
bool loadMessagesForItem(RootItem *item, QSqlTableModel *model); bool loadMessagesForItem(RootItem *item, QSqlTableModel *model);