Moved import/export actions to service root. Main form class is now not specific and contains only general code.

This commit is contained in:
Martin Rotter 2015-11-11 08:21:17 +01:00
parent cdb51c1a9a
commit 17ee15b87f
8 changed files with 65 additions and 74 deletions

@ -92,8 +92,6 @@ QList<QAction*> FormMain::allActions() {
// Add basic actions.
actions << m_ui->m_actionSettings;
actions << m_ui->m_actionDownloadManager;
actions << m_ui->m_actionImportFeeds;
actions << m_ui->m_actionExportFeeds;
actions << m_ui->m_actionRestoreDatabaseSettings;
actions << m_ui->m_actionBackupDatabaseSettings;
actions << m_ui->m_actionRestart;
@ -124,8 +122,8 @@ QList<QAction*> FormMain::allActions() {
actions << m_ui->m_actionMarkSelectedMessagesAsUnread;
actions << m_ui->m_actionSwitchImportanceOfSelectedMessages;
actions << m_ui->m_actionDeleteSelectedMessages;
actions << m_ui->m_actionUpdateAllFeeds;
actions << m_ui->m_actionUpdateSelectedFeeds;
actions << m_ui->m_actionUpdateAllItems;
actions << m_ui->m_actionUpdateSelectedItems;
actions << m_ui->m_actionEditSelectedItem;
actions << m_ui->m_actionDeleteSelectedItem;
actions << m_ui->m_actionViewSelectedItemsNewspaperMode;
@ -150,7 +148,7 @@ void FormMain::prepareMenus() {
// Add needed items to the menu.
m_trayMenu->addAction(m_ui->m_actionSwitchMainWindow);
m_trayMenu->addSeparator();
m_trayMenu->addAction(m_ui->m_actionUpdateAllFeeds);
m_trayMenu->addAction(m_ui->m_actionUpdateAllItems);
m_trayMenu->addAction(m_ui->m_actionMarkAllFeedsRead);
m_trayMenu->addSeparator();
m_trayMenu->addAction(m_ui->m_actionSettings);
@ -272,8 +270,6 @@ void FormMain::setupIcons() {
m_ui->m_actionCleanupDatabase->setIcon(icon_theme_factory->fromTheme(QSL("cleanup-database")));
m_ui->m_actionReportBugGitHub->setIcon(icon_theme_factory->fromTheme(QSL("application-report-bug")));
m_ui->m_actionReportBugBitBucket->setIcon(icon_theme_factory->fromTheme(QSL("application-report-bug")));
m_ui->m_actionExportFeeds->setIcon(icon_theme_factory->fromTheme(QSL("document-export")));
m_ui->m_actionImportFeeds->setIcon(icon_theme_factory->fromTheme(QSL("document-import")));
m_ui->m_actionBackupDatabaseSettings->setIcon(icon_theme_factory->fromTheme(QSL("document-export")));
m_ui->m_actionRestoreDatabaseSettings->setIcon(icon_theme_factory->fromTheme(QSL("document-import")));
m_ui->m_actionDonate->setIcon(icon_theme_factory->fromTheme(QSL("application-donate")));
@ -301,8 +297,8 @@ void FormMain::setupIcons() {
// Feeds/messages.
m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme(QSL("item-new")));
m_ui->m_actionUpdateAllFeeds->setIcon(icon_theme_factory->fromTheme(QSL("item-update-all")));
m_ui->m_actionUpdateSelectedFeeds->setIcon(icon_theme_factory->fromTheme(QSL("item-update-selected")));
m_ui->m_actionUpdateAllItems->setIcon(icon_theme_factory->fromTheme(QSL("item-update-all")));
m_ui->m_actionUpdateSelectedItems->setIcon(icon_theme_factory->fromTheme(QSL("item-update-selected")));
m_ui->m_actionClearSelectedFeeds->setIcon(icon_theme_factory->fromTheme(QSL("mail-remove")));
m_ui->m_actionClearAllFeeds->setIcon(icon_theme_factory->fromTheme(QSL("mail-remove")));
m_ui->m_actionDeleteSelectedItem->setIcon(icon_theme_factory->fromTheme(QSL("item-remove")));
@ -399,8 +395,6 @@ void FormMain::createConnections() {
connect(m_ui->m_menuServices, SIGNAL(aboutToShow()), this, SLOT(updateServicesMenu()));
// Menu "File" connections.
connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds()));
connect(m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds()));
connect(m_ui->m_actionBackupDatabaseSettings, SIGNAL(triggered()), this, SLOT(backupDatabaseSettings()));
connect(m_ui->m_actionRestoreDatabaseSettings, SIGNAL(triggered()), this, SLOT(restoreDatabaseSettings()));
connect(m_ui->m_actionRestart, SIGNAL(triggered()), qApp, SLOT(restart()));
@ -457,22 +451,6 @@ void FormMain::loadWebBrowserMenu(int index) {
m_ui->m_actionCloseCurrentTab->setEnabled(m_ui->m_tabWidget->tabBar()->tabType(index) == TabBar::Closable);
}
void FormMain::exportFeeds() {
QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
this);
form.data()->setMode(FeedsImportExportModel::Export);
form.data()->exec();
delete form.data();
}
void FormMain::importFeeds() {
QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
this);
form.data()->setMode(FeedsImportExportModel::Import);
form.data()->exec();
delete form.data();
}
void FormMain::backupDatabaseSettings() {
QPointer<FormBackupDatabaseSettings> form = new FormBackupDatabaseSettings(this);
form.data()->exec();

@ -85,8 +85,6 @@ class FormMain : public QMainWindow {
void loadWebBrowserMenu(int index);
// Displays various dialogs.
void exportFeeds();
void importFeeds();
void backupDatabaseSettings();
void restoreDatabaseSettings();
void showSettings();

@ -55,9 +55,6 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="m_actionImportFeeds"/>
<addaction name="m_actionExportFeeds"/>
<addaction name="separator"/>
<addaction name="m_actionRestoreDatabaseSettings"/>
<addaction name="m_actionBackupDatabaseSettings"/>
<addaction name="separator"/>
@ -135,8 +132,8 @@
<string>Add &amp;new item</string>
</property>
</widget>
<addaction name="m_actionUpdateAllFeeds"/>
<addaction name="m_actionUpdateSelectedFeeds"/>
<addaction name="m_actionUpdateAllItems"/>
<addaction name="m_actionUpdateSelectedItems"/>
<addaction name="separator"/>
<addaction name="m_menuAddItem"/>
<addaction name="m_actionEditSelectedItem"/>
@ -267,20 +264,20 @@
<string>Close current web browser tab.</string>
</property>
</action>
<action name="m_actionUpdateAllFeeds">
<action name="m_actionUpdateAllItems">
<property name="text">
<string>Update &amp;all items</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+U</string>
<string>Ctrl+Shift+U</string>
</property>
</action>
<action name="m_actionUpdateSelectedFeeds">
<action name="m_actionUpdateSelectedItems">
<property name="text">
<string>Update &amp;selected items</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+U</string>
<string>Ctrl+U</string>
</property>
</action>
<action name="m_actionEditSelectedItem">
@ -310,7 +307,7 @@
</action>
<action name="m_actionMarkSelectedFeedsAsRead">
<property name="text">
<string>&amp;Mark selected feeds as read</string>
<string>&amp;Mark selected items as read</string>
</property>
<property name="toolTip">
<string>Mark all messages (without message filters) from selected feeds as read.</string>
@ -318,7 +315,7 @@
</action>
<action name="m_actionMarkSelectedFeedsAsUnread">
<property name="text">
<string>&amp;Mark selected feeds as unread</string>
<string>&amp;Mark selected items as unread</string>
</property>
<property name="toolTip">
<string>Mark all messages (without message filters) from selected feeds as unread.</string>
@ -331,7 +328,7 @@
</action>
<action name="m_actionClearSelectedFeeds">
<property name="text">
<string>&amp;Clean selected feeds</string>
<string>&amp;Clean selected items</string>
</property>
<property name="toolTip">
<string>Deletes all messages from selected feeds.</string>
@ -365,7 +362,7 @@
</action>
<action name="m_actionMarkAllFeedsRead">
<property name="text">
<string>&amp;Mark all feeds as &amp;read</string>
<string>&amp;Mark all items as &amp;read</string>
</property>
<property name="toolTip">
<string>Marks all messages in all feeds read. This does not take message filters into account.</string>
@ -373,7 +370,7 @@
</action>
<action name="m_actionViewSelectedItemsNewspaperMode">
<property name="text">
<string>View selected feeds in &amp;newspaper mode</string>
<string>View selected items in &amp;newspaper mode</string>
</property>
<property name="toolTip">
<string>Displays all messages from selected feeds/categories in a new &quot;newspaper mode&quot; tab. Note that messages are not set as read automatically.</string>
@ -406,7 +403,7 @@
</action>
<action name="m_actionClearAllFeeds">
<property name="text">
<string>&amp;Clean all feeds</string>
<string>&amp;Clean all items</string>
</property>
<property name="toolTip">
<string>Deletes all messages from all feeds.</string>
@ -544,22 +541,6 @@
<string notr="true">H</string>
</property>
</action>
<action name="m_actionImportFeeds">
<property name="text">
<string>&amp;Import feeds</string>
</property>
<property name="toolTip">
<string>Imports feeds you want from selected file.</string>
</property>
</action>
<action name="m_actionExportFeeds">
<property name="text">
<string>&amp;Export feeds</string>
</property>
<property name="toolTip">
<string>Exports feeds you want to selected file.</string>
</property>
</action>
<action name="m_actionReportBugBitBucket">
<property name="text">
<string>Report a bug (BitBucket)...</string>
@ -624,7 +605,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Show only unread feeds/categories</string>
<string>Show only unread items</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Shift+U</string>
@ -632,7 +613,7 @@
</action>
<action name="m_actionExpandCollapseFeedCategory">
<property name="text">
<string>&amp;Expand/collapse selected feed/category</string>
<string>&amp;Expand/collapse selected item</string>
</property>
<property name="shortcut">
<string notr="true">E</string>

@ -292,16 +292,17 @@ void FeedMessageViewer::updateFeedButtonsAvailability() {
bool service_selected = anything_selected && selected_item->kind() == RootItemKind::ServiceRoot;
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_actionCleanupDatabase->setEnabled(!critical_action_running);
form_main->m_ui->m_actionClearSelectedFeeds->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_actionDeleteSelectedItem->setEnabled(!critical_action_running && anything_selected);
form_main->m_ui->m_actionEditSelectedItem->setEnabled(!critical_action_running && anything_selected);
form_main->m_ui->m_actionImportFeeds->setEnabled(!critical_action_running);
form_main->m_ui->m_actionMarkSelectedFeedsAsRead->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_actionMarkSelectedFeedsAsUnread->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_actionUpdateAllFeeds->setEnabled(!critical_action_running);
form_main->m_ui->m_actionUpdateSelectedFeeds->setEnabled(!critical_action_running && (feed_selected || category_selected || service_selected));
form_main->m_ui->m_actionUpdateAllItems->setEnabled(!critical_action_running);
form_main->m_ui->m_actionUpdateSelectedItems->setEnabled(!critical_action_running && (feed_selected || category_selected || service_selected));
form_main->m_ui->m_actionViewSelectedItemsNewspaperMode->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_actionExpandCollapseFeedCategory->setEnabled(feed_selected || category_selected || service_selected);
form_main->m_ui->m_menuAddItem->setEnabled(!critical_action_running);
@ -381,9 +382,9 @@ void FeedMessageViewer::createConnections() {
SIGNAL(triggered()), m_feedsView, SLOT(clearSelectedFeeds()));
connect(form_main->m_ui->m_actionClearAllFeeds,
SIGNAL(triggered()), m_feedsView, SLOT(clearAllFeeds()));
connect(form_main->m_ui->m_actionUpdateSelectedFeeds,
connect(form_main->m_ui->m_actionUpdateSelectedItems,
SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedFeeds()));
connect(form_main->m_ui->m_actionUpdateAllFeeds,
connect(form_main->m_ui->m_actionUpdateAllItems,
SIGNAL(triggered()), m_feedsView, SLOT(updateAllFeeds()));
connect(form_main->m_ui->m_actionEditSelectedItem,
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));

@ -494,7 +494,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
QList<QAction*> specific_actions = clicked_item->contextMenuActions();
m_contextMenuCategories->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedItems <<
qApp->mainForm()->m_ui->m_actionEditSelectedItem <<
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode <<
qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsRead <<
@ -518,7 +518,7 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) {
QList<QAction*> specific_actions = clicked_item->contextMenuActions();
m_contextMenuFeeds->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedItems <<
qApp->mainForm()->m_ui->m_actionEditSelectedItem <<
qApp->mainForm()->m_ui->m_actionViewSelectedItemsNewspaperMode <<
qApp->mainForm()->m_ui->m_actionMarkSelectedFeedsAsRead <<
@ -533,7 +533,7 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) {
void FeedsView::initializeContextMenuEmptySpace() {
m_contextMenuEmptySpace = new QMenu(tr("Context menu for empty space"), this);
m_contextMenuEmptySpace->addAction(qApp->mainForm()->m_ui->m_actionUpdateAllFeeds);
m_contextMenuEmptySpace->addAction(qApp->mainForm()->m_ui->m_actionUpdateAllItems);
m_contextMenuEmptySpace->addSeparator();
}

@ -82,7 +82,7 @@ DKEY GUI::ToolbarStyle = "toolbar_style";
DVALUE(Qt::ToolButtonStyle) GUI::ToolbarStyleDef = Qt::ToolButtonIconOnly;
DKEY GUI::FeedsToolbarActions = "feeds_toolbar";
DVALUE(char*) GUI::FeedsToolbarActionsDef = "m_actionUpdateAllFeeds,m_actionMarkAllFeedsRead";
DVALUE(char*) GUI::FeedsToolbarActionsDef = "m_actionUpdateAllItems,m_actionMarkAllFeedsRead";
DKEY GUI::MainWindowInitialSize = "window_size";
DKEY GUI::MainWindowInitialPosition = "window_position";

@ -21,6 +21,7 @@
#include "miscellaneous/application.h"
#include "miscellaneous/settings.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include "core/feedsmodel.h"
#include "gui/messagebox.h"
#include "gui/dialogs/formmain.h"
@ -32,6 +33,7 @@
#include "services/standard/standardfeedsimportexportmodel.h"
#include "services/standard/gui/formstandardcategorydetails.h"
#include "services/standard/gui/formstandardfeeddetails.h"
#include "services/standard/gui/formstandardimportexport.h"
#include <QSqlQuery>
#include <QSqlError>
@ -43,6 +45,7 @@
StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent)
: ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)),
m_actionExportFeeds(NULL), m_actionImportFeeds(NULL), m_serviceMenu(QList<QAction*>()),
m_addItemMenu(QList<QAction*>()), m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(NULL) {
setTitle(qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME));
setIcon(StandardServiceEntryPoint().icon());
@ -55,6 +58,7 @@ StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_mo
}
StandardServiceRoot::~StandardServiceRoot() {
qDeleteAll(m_serviceMenu);
qDeleteAll(m_addItemMenu);
qDeleteAll(m_feedContextMenu);
}
@ -334,18 +338,30 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model,
void StandardServiceRoot::addNewCategory() {
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(this, qApp->mainForm());
form_pointer.data()->exec(NULL, NULL);
delete form_pointer.data();
}
void StandardServiceRoot::addNewFeed() {
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(this, qApp->mainForm());
form_pointer.data()->exec(NULL, NULL);
delete form_pointer.data();
}
void StandardServiceRoot::importFeeds() {
QPointer<FormStandardImportExport> form = new FormStandardImportExport(this, qApp->mainForm());
form.data()->setMode(FeedsImportExportModel::Import);
form.data()->exec();
delete form.data();
}
void StandardServiceRoot::exportFeeds() {
QPointer<FormStandardImportExport> form = new FormStandardImportExport(this, qApp->mainForm());
form.data()->setMode(FeedsImportExportModel::Export);
form.data()->exec();
delete form.data();
}
QList<QAction*> StandardServiceRoot::addItemMenu() {
if (m_addItemMenu.isEmpty()) {
QAction *action_new_category = new QAction(qApp->icons()->fromTheme("folder-category"), tr("Add new category"), this);
@ -362,7 +378,18 @@ QList<QAction*> StandardServiceRoot::addItemMenu() {
}
QList<QAction*> StandardServiceRoot::serviceMenu() {
return m_addItemMenu;
if (m_serviceMenu.isEmpty()) {
m_actionExportFeeds = new QAction(qApp->icons()->fromTheme("document-export"), tr("Export feeds"), this);
m_actionImportFeeds = new QAction(qApp->icons()->fromTheme("document-import"), tr("Import feeds"), this);
connect(m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds()));
connect(m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds()));
m_serviceMenu.append(m_actionExportFeeds);
m_serviceMenu.append(m_actionImportFeeds);
}
return m_serviceMenu;
}
void StandardServiceRoot::assembleCategories(CategoryAssignment categories) {

@ -77,6 +77,8 @@ class StandardServiceRoot : public ServiceRoot {
public slots:
void addNewCategory();
void addNewFeed();
void importFeeds();
void exportFeeds();
private:
void loadFromDatabase();
@ -89,6 +91,10 @@ class StandardServiceRoot : public ServiceRoot {
StandardRecycleBin *m_recycleBin;
// Menus.
QAction *m_actionExportFeeds;
QAction *m_actionImportFeeds;
QList<QAction*> m_serviceMenu;
QList<QAction*> m_addItemMenu;
QList<QAction*> m_feedContextMenu;