Import/export now works, some minor fixing.

This commit is contained in:
Martin Rotter 2015-11-06 11:30:39 +01:00
parent 3d59902aeb
commit 779f42f5dd
13 changed files with 60 additions and 41 deletions

View file

@ -41,7 +41,7 @@ RootItem::~RootItem() {
qDeleteAll(m_childItems); qDeleteAll(m_childItems);
} }
QList<QAction *> RootItem::specificActions() { QList<QAction *> RootItem::specificContextMenuActions() {
return QList<QAction*>(); return QList<QAction*>();
} }

View file

@ -80,7 +80,7 @@ class RootItem : public QObject {
// NOTE: This method should always create new actions in memory // NOTE: This method should always create new actions in memory
// before returning them because caller takes ownership of any // before returning them because caller takes ownership of any
// actions returned from here. // actions returned from here.
virtual QList<QAction*> specificActions(); virtual QList<QAction*> specificContextMenuActions();
// TODO: pracovat s těmito věcmi // TODO: pracovat s těmito věcmi
virtual bool canBeEdited() { virtual bool canBeEdited() {

View file

@ -395,25 +395,21 @@ void FormMain::loadWebBrowserMenu(int index) {
} }
void FormMain::exportFeeds() { void FormMain::exportFeeds() {
// TODO: dodelat globalni pristup ke globalnimu standard service rootu, // TODO: crash
// ten předat QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
/* this);
QPointer<FormStandardImportExport> form = new FormStandardImportExport(this);
form.data()->setMode(FeedsImportExportModel::Export); form.data()->setMode(FeedsImportExportModel::Export);
form.data()->exec(); form.data()->exec();
delete form.data(); delete form.data();
*/
} }
void FormMain::importFeeds() { void FormMain::importFeeds() {
// TODO: dodelat globalni pristup ke globalnimu standard service rootu, // TODO: crash
// ten předat QPointer<FormStandardImportExport> form = new FormStandardImportExport(tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->standardServiceRoot(),
/* this);
QPointer<FormStandardImportExport> form = new FormStandardImportExport(this);
form.data()->setMode(FeedsImportExportModel::Import); form.data()->setMode(FeedsImportExportModel::Import);
form.data()->exec(); form.data()->exec();
delete form.data(); delete form.data();
*/
} }
void FormMain::backupDatabaseSettings() { void FormMain::backupDatabaseSettings() {

View file

@ -64,19 +64,6 @@ class FormMain : public QMainWindow {
void loadSize(); void loadSize();
void saveSize(); 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: public slots:
// Displays window on top or switches its visibility. // Displays window on top or switches its visibility.
void display(); void display();
@ -90,7 +77,7 @@ class FormMain : public QMainWindow {
// Switches visibility of main menu. // Switches visibility of main menu.
void switchMainMenu(); void switchMainMenu();
protected slots: private slots:
// Loads web browser menu if user selects to change tabs. // Loads web browser menu if user selects to change tabs.
void loadWebBrowserMenu(int index); void loadWebBrowserMenu(int index);
@ -108,6 +95,18 @@ class FormMain : public QMainWindow {
void donate(); void donate();
private: 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; Ui::FormMain *m_ui;
QMenu *m_trayMenu; QMenu *m_trayMenu;
StatusBar *m_statusBar; StatusBar *m_statusBar;

View file

@ -491,7 +491,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
m_contextMenuCategories->clear(); m_contextMenuCategories->clear();
} }
QList<QAction*> specific_actions = clicked_item->specificActions(); QList<QAction*> specific_actions = clicked_item->specificContextMenuActions();
m_contextMenuCategories->addActions(QList<QAction*>() << m_contextMenuCategories->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << 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); m_contextMenuFeeds = new QMenu(tr("Context menu for categories"), this);
} }
else { 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(); m_contextMenuFeeds->clear();
} }
QList<QAction*> specific_actions = clicked_item->specificActions(); QList<QAction*> specific_actions = clicked_item->specificContextMenuActions();
m_contextMenuFeeds->addActions(QList<QAction*>() << m_contextMenuFeeds->addActions(QList<QAction*>() <<
qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds << qApp->mainForm()->m_ui->m_actionUpdateSelectedFeeds <<
@ -604,6 +606,9 @@ void FeedsView::contextMenuEvent(QContextMenuEvent *event) {
initializeContextMenuFeeds(clicked_item); initializeContextMenuFeeds(clicked_item);
m_contextMenuFeeds->exec(event->globalPos()); m_contextMenuFeeds->exec(event->globalPos());
} }
else {
}
} }
else { else {
// Display menu for empty space. // Display menu for empty space.

View file

@ -33,6 +33,16 @@ class ServiceRoot : public RootItem {
explicit ServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL); explicit ServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL);
virtual ~ServiceRoot(); 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<QAction*> specificAddItemActions() = 0;
inline FeedsModel *feedsModel() const { inline FeedsModel *feedsModel() const {
return m_feedsModel; return m_feedsModel;
} }

View file

@ -158,7 +158,7 @@ bool StandardCategory::removeItself() {
} }
if (children_removed) { 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); QSqlDatabase database = qApp->database()->connection(QSL("Category"), DatabaseFactory::FromSettings);
QSqlQuery query_remove(database); QSqlQuery query_remove(database);
@ -176,7 +176,6 @@ bool StandardCategory::removeItself() {
bool StandardCategory::addItself(RootItem *parent) { bool StandardCategory::addItself(RootItem *parent) {
// Now, add category to persistent storage. // Now, add category to persistent storage.
// Children are removed, remove this standard category too.
QSqlDatabase database = qApp->database()->connection(QSL("Category"), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(QSL("Category"), DatabaseFactory::FromSettings);
QSqlQuery query_add(database); QSqlQuery query_add(database);

View file

@ -99,7 +99,7 @@ int StandardFeed::countOfUnreadMessages() const {
return m_unreadCount; return m_unreadCount;
} }
QList<QAction*> StandardFeed::specificActions() { QList<QAction*> StandardFeed::specificContextMenuActions() {
return serviceRoot()->getMenuForFeed(this); return serviceRoot()->getMenuForFeed(this);
} }

View file

@ -61,7 +61,7 @@ class StandardFeed : public Feed {
int countOfAllMessages() const; int countOfAllMessages() const;
int countOfUnreadMessages() const; int countOfUnreadMessages() const;
QList<QAction*> specificActions(); QList<QAction*> specificContextMenuActions();
bool canBeEdited() { bool canBeEdited() {
return true; return true;

View file

@ -19,6 +19,7 @@
#include "services/standard/standardfeed.h" #include "services/standard/standardfeed.h"
#include "services/standard/standardcategory.h" #include "services/standard/standardcategory.h"
#include "services/standard/standardserviceroot.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
@ -166,7 +167,7 @@ bool FeedsImportExportModel::importAsOPML20(const QByteArray &data) {
return false; return false;
} }
RootItem *root_item = new RootItem(); StandardServiceRoot *root_item = new StandardServiceRoot(false, NULL, NULL);
QStack<RootItem*> model_items; model_items.push(root_item); QStack<RootItem*> model_items; model_items.push(root_item);
QStack<QDomElement> elements_to_process; elements_to_process.push(opml_document.documentElement().elementsByTagName(QSL("body")).at(0).toElement()); QStack<QDomElement> 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 { 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. // Root item lies on invalid index.
return QModelIndex(); return QModelIndex();
} }

View file

@ -70,7 +70,7 @@ QIcon StandardServiceEntryPoint::icon() {
} }
QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree(FeedsModel *main_model) { QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree(FeedsModel *main_model) {
StandardServiceRoot *root = new StandardServiceRoot(main_model); StandardServiceRoot *root = new StandardServiceRoot(true, main_model);
QList<ServiceRoot*> roots; QList<ServiceRoot*> roots;
roots.append(root); roots.append(root);

View file

@ -34,14 +34,16 @@
#include <QCoreApplication> #include <QCoreApplication>
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)) { : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) {
m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME); m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME);
m_icon = StandardServiceEntryPoint().icon(); m_icon = StandardServiceEntryPoint().icon();
m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."); m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.");
m_creationDate = QDateTime::currentDateTime(); m_creationDate = QDateTime::currentDateTime();
loadFromDatabase(); if (load_from_db) {
loadFromDatabase();
}
} }
StandardServiceRoot::~StandardServiceRoot() { 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) { if (some_feed_category_error) {
output_message = tr("Import successfull, but some feeds/categories were not imported due to 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; return !some_feed_category_error;
} }
QList<QAction*> StandardServiceRoot::specificAddItemActions() {
QList<QAction*> actions;
// TODO: vracet add feed, add category
actions.append(new QAction("abc", NULL));
return actions;
}
void StandardServiceRoot::assembleCategories(CategoryAssignment categories) { void StandardServiceRoot::assembleCategories(CategoryAssignment categories) {
QHash<int, RootItem*> assignments; QHash<int, RootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, this); assignments.insert(NO_PARENT_CATEGORY, this);

View file

@ -38,7 +38,7 @@ class StandardServiceRoot : public ServiceRoot {
Q_OBJECT Q_OBJECT
public: public:
explicit StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL); explicit StandardServiceRoot(bool load_from_db, FeedsModel *feeds_model, RootItem *parent = NULL);
virtual ~StandardServiceRoot(); virtual ~StandardServiceRoot();
bool canBeEdited(); bool canBeEdited();
@ -63,6 +63,8 @@ class StandardServiceRoot : public ServiceRoot {
// NOTE: This is used for import/export of the model. // NOTE: This is used for import/export of the model.
bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message); bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message);
QList<QAction*> specificAddItemActions();
private: private:
void loadFromDatabase(); void loadFromDatabase();