diff --git a/src/core/rootitem.cpp b/src/core/rootitem.cpp index dc48504c4..0892160ac 100755 --- a/src/core/rootitem.cpp +++ b/src/core/rootitem.cpp @@ -41,7 +41,7 @@ RootItem::~RootItem() { qDeleteAll(m_childItems); } -QList RootItem::specificActions() { +QList RootItem::specificContextMenuActions() { return QList(); } diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 8d25ecf89..3591023e7 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -80,7 +80,7 @@ class RootItem : public QObject { // NOTE: This method should always create new actions in memory // before returning them because caller takes ownership of any // actions returned from here. - virtual QList specificActions(); + virtual QList specificContextMenuActions(); // TODO: pracovat s těmito věcmi virtual bool canBeEdited() { diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index 738509e84..c1b8e7d60 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -395,25 +395,21 @@ void FormMain::loadWebBrowserMenu(int index) { } void FormMain::exportFeeds() { - // TODO: dodelat globalni pristup ke globalnimu standard service rootu, - // ten předat - /* - QPointer form = new FormStandardImportExport(this); + // TODO: crash + QPointer form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(), + this); form.data()->setMode(FeedsImportExportModel::Export); form.data()->exec(); delete form.data(); - */ } void FormMain::importFeeds() { - // TODO: dodelat globalni pristup ke globalnimu standard service rootu, - // ten předat - /* - QPointer form = new FormStandardImportExport(this); + // TODO: crash + QPointer form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(), + this); form.data()->setMode(FeedsImportExportModel::Import); form.data()->exec(); delete form.data(); - */ } void FormMain::backupDatabaseSettings() { diff --git a/src/gui/dialogs/formmain.h b/src/gui/dialogs/formmain.h index 39d2c62bf..7537acdcd 100755 --- a/src/gui/dialogs/formmain.h +++ b/src/gui/dialogs/formmain.h @@ -64,19 +64,6 @@ class FormMain : public QMainWindow { void loadSize(); void saveSize(); - protected: - // Creates all needed menus and sets them up. - void prepareMenus(); - - // Creates needed connections for this window. - void createConnections(); - - // Event handler reimplementations. - void changeEvent(QEvent *event); - - // Sets up proper icons for this widget. - void setupIcons(); - public slots: // Displays window on top or switches its visibility. void display(); @@ -90,7 +77,7 @@ class FormMain : public QMainWindow { // Switches visibility of main menu. void switchMainMenu(); - protected slots: + private slots: // Loads web browser menu if user selects to change tabs. void loadWebBrowserMenu(int index); @@ -108,6 +95,18 @@ class FormMain : public QMainWindow { void donate(); private: + // Event handler reimplementations. + void changeEvent(QEvent *event); + + // Creates all needed menus and sets them up. + void prepareMenus(); + + // Creates needed connections for this window. + void createConnections(); + + // Sets up proper icons for this widget. + void setupIcons(); + Ui::FormMain *m_ui; QMenu *m_trayMenu; StatusBar *m_statusBar; diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index ab3a57ac6..759e320fd 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -491,7 +491,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) { m_contextMenuCategories->clear(); } - QList specific_actions = clicked_item->specificActions(); + QList specific_actions = clicked_item->specificContextMenuActions(); m_contextMenuCategories->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << @@ -512,10 +512,12 @@ void FeedsView::initializeContextMenuFeeds(RootItem *clicked_item) { m_contextMenuFeeds = new QMenu(tr("Context menu for categories"), this); } else { + // FIXME: Položky jsou mazány při opětovném otevření kontextového nabíky ale je lepší je mazat + // hned při zavření kontextove nabíky. m_contextMenuFeeds->clear(); } - QList specific_actions = clicked_item->specificActions(); + QList specific_actions = clicked_item->specificContextMenuActions(); m_contextMenuFeeds->addActions(QList() << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << @@ -604,6 +606,9 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) { initializeContextMenuFeeds(clicked_item); m_contextMenuFeeds->exec(event->globalPos()); } + else { + + } } else { // Display menu for empty space. diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index 86315accc..ebcc8a11a 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -33,6 +33,16 @@ class ServiceRoot : public RootItem { explicit ServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL); virtual ~ServiceRoot(); + // Returns list of specific actions for "Add new item" main window menu. + // So typical list of returned actions could look like: + // a) Add new feed + // b) Add new category + // c) ... + // NOTE: This method should always create new actions in memory + // before returning them because caller takes ownership of any + // actions returned from here. + virtual QList specificAddItemActions() = 0; + inline FeedsModel *feedsModel() const { return m_feedsModel; } diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index a5d62b8ff..24503c6e3 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -158,7 +158,7 @@ bool StandardCategory::removeItself() { } if (children_removed) { - // Children are removed, remove this standard category too. + // Children are removed, remove this standard category too. QSqlDatabase database = qApp->database()->connection(QSL("Category"), DatabaseFactory::FromSettings); QSqlQuery query_remove(database); @@ -176,7 +176,6 @@ bool StandardCategory::removeItself() { bool StandardCategory::addItself(RootItem *parent) { // Now, add category to persistent storage. - // Children are removed, remove this standard category too. QSqlDatabase database = qApp->database()->connection(QSL("Category"), DatabaseFactory::FromSettings); QSqlQuery query_add(database); diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 7f9511148..c175a1b66 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -99,7 +99,7 @@ int StandardFeed::countOfUnreadMessages() const { return m_unreadCount; } -QList StandardFeed::specificActions() { +QList StandardFeed::specificContextMenuActions() { return serviceRoot()->getMenuForFeed(this); } diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 2abb87439..af642320f 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -61,7 +61,7 @@ class StandardFeed : public Feed { int countOfAllMessages() const; int countOfUnreadMessages() const; - QList specificActions(); + QList specificContextMenuActions(); bool canBeEdited() { return true; diff --git a/src/services/standard/standardfeedsimportexportmodel.cpp b/src/services/standard/standardfeedsimportexportmodel.cpp index 3133be8a3..837ebc3f6 100755 --- a/src/services/standard/standardfeedsimportexportmodel.cpp +++ b/src/services/standard/standardfeedsimportexportmodel.cpp @@ -19,6 +19,7 @@ #include "services/standard/standardfeed.h" #include "services/standard/standardcategory.h" +#include "services/standard/standardserviceroot.h" #include "definitions/definitions.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -166,7 +167,7 @@ bool FeedsImportExportModel::importAsOPML20(const QByteArray &data) { return false; } - RootItem *root_item = new RootItem(); + StandardServiceRoot *root_item = new StandardServiceRoot(false, NULL, NULL); QStack model_items; model_items.push(root_item); QStack elements_to_process; elements_to_process.push(opml_document.documentElement().elementsByTagName(QSL("body")).at(0).toElement()); @@ -295,7 +296,7 @@ QModelIndex FeedsImportExportModel::index(int row, int column, const QModelIndex } QModelIndex FeedsImportExportModel::indexForItem(RootItem *item) const { - if (item == NULL || item->kind() == RootItemKind::Root) { + if (item == NULL || item->kind() == RootItemKind::ServiceRoot || item->kind() == RootItemKind::Root) { // Root item lies on invalid index. return QModelIndex(); } diff --git a/src/services/standard/standardserviceentrypoint.cpp b/src/services/standard/standardserviceentrypoint.cpp index de70987d7..3156a927c 100755 --- a/src/services/standard/standardserviceentrypoint.cpp +++ b/src/services/standard/standardserviceentrypoint.cpp @@ -70,7 +70,7 @@ QIcon StandardServiceEntryPoint::icon() { } QList StandardServiceEntryPoint::initializeSubtree(FeedsModel *main_model) { - StandardServiceRoot *root = new StandardServiceRoot(main_model); + StandardServiceRoot *root = new StandardServiceRoot(true, main_model); QList roots; roots.append(root); diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index d776f406f..0536b69be 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -34,14 +34,16 @@ #include -StandardServiceRoot::StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent) +StandardServiceRoot::StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent) : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) { m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME); m_icon = StandardServiceEntryPoint().icon(); m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."); m_creationDate = QDateTime::currentDateTime(); - loadFromDatabase(); + if (load_from_db) { + loadFromDatabase(); + } } StandardServiceRoot::~StandardServiceRoot() { @@ -312,9 +314,6 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, } } - // Changes are done now. Finalize the new model. - //emit layoutChanged(); - if (some_feed_category_error) { output_message = tr("Import successfull, but some feeds/categories were not imported due to error."); } @@ -325,6 +324,14 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, return !some_feed_category_error; } +QList StandardServiceRoot::specificAddItemActions() { + QList actions; + + // TODO: vracet add feed, add category + actions.append(new QAction("abc", NULL)); + return actions; +} + void StandardServiceRoot::assembleCategories(CategoryAssignment categories) { QHash assignments; assignments.insert(NO_PARENT_CATEGORY, this); diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h index 835b9c81a..9309b35f3 100755 --- a/src/services/standard/standardserviceroot.h +++ b/src/services/standard/standardserviceroot.h @@ -38,7 +38,7 @@ class StandardServiceRoot : public ServiceRoot { Q_OBJECT public: - explicit StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL); + explicit StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent = NULL); virtual ~StandardServiceRoot(); bool canBeEdited(); @@ -63,6 +63,8 @@ class StandardServiceRoot : public ServiceRoot { // NOTE: This is used for import/export of the model. bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message); + QList specificAddItemActions(); + private: void loadFromDatabase();