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);
}
QList<QAction *> RootItem::specificActions() {
QList<QAction *> RootItem::specificContextMenuActions() {
return QList<QAction*>();
}

View File

@ -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<QAction*> specificActions();
virtual QList<QAction*> specificContextMenuActions();
// TODO: pracovat s těmito věcmi
virtual bool canBeEdited() {

View File

@ -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<FormStandardImportExport> form = new FormStandardImportExport(this);
// TODO: crash
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() {
// TODO: dodelat globalni pristup ke globalnimu standard service rootu,
// ten předat
/*
QPointer<FormStandardImportExport> form = new FormStandardImportExport(this);
// TODO: crash
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() {

View File

@ -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;

View File

@ -491,7 +491,7 @@ void FeedsView::initializeContextMenuCategories(RootItem *clicked_item) {
m_contextMenuCategories->clear();
}
QList<QAction*> specific_actions = clicked_item->specificActions();
QList<QAction*> specific_actions = clicked_item->specificContextMenuActions();
m_contextMenuCategories->addActions(QList<QAction*>() <<
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<QAction*> specific_actions = clicked_item->specificActions();
QList<QAction*> specific_actions = clicked_item->specificContextMenuActions();
m_contextMenuFeeds->addActions(QList<QAction*>() <<
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.

View File

@ -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<QAction*> specificAddItemActions() = 0;
inline FeedsModel *feedsModel() const {
return m_feedsModel;
}

View File

@ -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);

View File

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

View File

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

View File

@ -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<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());
@ -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();
}

View File

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

View File

@ -34,14 +34,16 @@
#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)) {
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<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) {
QHash<int, RootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, this);

View File

@ -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<QAction*> specificAddItemActions();
private:
void loadFromDatabase();