Deleting of items is now moved to interface.
This commit is contained in:
parent
39666e7bae
commit
5c0f777189
|
@ -208,27 +208,20 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool FeedsModel::removeItem(const QModelIndex &index) {
|
||||
void FeedsModel::removeItem(const QModelIndex &index) {
|
||||
if (index.isValid()) {
|
||||
QModelIndex parent_index = index.parent();
|
||||
RootItem *deleting_item = itemForIndex(index);
|
||||
RootItem *parent_item = deleting_item->parent();
|
||||
|
||||
// Try to persistently remove the item.
|
||||
if (deleting_item->removeItself()) {
|
||||
// Item was persistently removed.
|
||||
// Remove it from the model.
|
||||
beginRemoveRows(parent_index, index.row(), index.row());
|
||||
parent_item->removeChild(deleting_item);
|
||||
endRemoveRows();
|
||||
// Item was persistently removed.
|
||||
// Remove it from the model.
|
||||
beginRemoveRows(parent_index, index.row(), index.row());
|
||||
parent_item->removeChild(deleting_item);
|
||||
endRemoveRows();
|
||||
|
||||
delete deleting_item;
|
||||
return true;
|
||||
}
|
||||
delete deleting_item;
|
||||
}
|
||||
|
||||
// Item was not removed successfully.
|
||||
return false;
|
||||
}
|
||||
|
||||
void FeedsModel::reassignNodeToNewParent(RootItem *original_node, RootItem *new_parent) {
|
||||
|
|
|
@ -61,7 +61,7 @@ class FeedsModel : public QAbstractItemModel {
|
|||
|
||||
// Removes item with given index.
|
||||
// NOTE: Also deletes item from memory.
|
||||
bool removeItem(const QModelIndex &index);
|
||||
void removeItem(const QModelIndex &index);
|
||||
|
||||
// Checks if new parent node is different from one used by original node.
|
||||
// If it is, then it reassigns original_node to new parent.
|
||||
|
|
|
@ -78,7 +78,7 @@ class RootItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual bool editViaDialog() {
|
||||
virtual bool editViaGui() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,23 @@ class RootItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
virtual bool canBeMarkedAsRead() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool markAsRead() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool canBeMarkedAsUnread() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool markAsUnread() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual int row() const;
|
||||
virtual QVariant data(int column, int role) const;
|
||||
|
||||
|
@ -98,16 +115,6 @@ class RootItem {
|
|||
virtual int countOfUnreadMessages() const;
|
||||
virtual int countOfAllMessages() const;
|
||||
|
||||
// This method is used to permanently
|
||||
// "remove" (or "unregister") this item.
|
||||
// This typically removes item and its
|
||||
// "children" (for example messages or child feeds)
|
||||
// from the database.
|
||||
// Returns true if "I" was removed.
|
||||
virtual bool removeItself() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Access to children.
|
||||
inline QList<RootItem*> childItems() const {
|
||||
return m_childItems;
|
||||
|
|
|
@ -247,7 +247,7 @@ void FeedsView::editSelectedItem() {
|
|||
}
|
||||
|
||||
if (selectedItem()->canBeEdited()) {
|
||||
selectedItem()->editViaDialog();
|
||||
selectedItem()->editViaGui();
|
||||
}
|
||||
else {
|
||||
qApp->showGuiMessage(tr("Cannot edit item"),
|
||||
|
@ -282,24 +282,47 @@ void FeedsView::deleteSelectedItem() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (MessageBox::show(qApp->mainForm(), QMessageBox::Question, tr("Delete feed/category"),
|
||||
tr("You are about to delete selected feed or category."), tr("Do you really want to delete selected item?"),
|
||||
QString(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) {
|
||||
// User changed his mind.
|
||||
qApp->feedUpdateLock()->unlock();
|
||||
return;
|
||||
}
|
||||
RootItem *selected_item = selectedItem();
|
||||
|
||||
if (m_sourceModel->removeItem(m_proxyModel->mapToSource(current_index))) {
|
||||
// Item WAS removed, update counts.
|
||||
notifyWithCounts();
|
||||
}
|
||||
else {
|
||||
// Item WAS NOT removed, either database-related error occurred
|
||||
// or update is undergoing.
|
||||
qApp->showGuiMessage(tr("Deletion of item failed."),
|
||||
tr("Selected item was not deleted due to error."),
|
||||
QSystemTrayIcon::Warning, qApp->mainForm(), true);
|
||||
if (selected_item != NULL) {
|
||||
if (selected_item->canBeDeleted()) {
|
||||
// Ask user first.
|
||||
if (MessageBox::show(qApp->mainForm(),
|
||||
QMessageBox::Question,
|
||||
tr("Deleting \"%1\"").arg(selected_item->title()),
|
||||
tr("You are about to completely delete item \"%1\".").arg(selected_item->title()),
|
||||
tr("Are you sure?"),
|
||||
QString(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) {
|
||||
// User refused.
|
||||
qApp->feedUpdateLock()->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// We have deleteable item selected, remove it via GUI.
|
||||
if (!selected_item->deleteViaGui()) {
|
||||
qApp->showGuiMessage(tr("Cannot delete \"%1\"").arg(selected_item->title()),
|
||||
tr("This item cannot be deleted because something critically failed. Submit bug report."),
|
||||
QSystemTrayIcon::Critical,
|
||||
qApp->mainForm(),
|
||||
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));
|
||||
notifyWithCounts();
|
||||
}
|
||||
}
|
||||
else {
|
||||
qApp->showGuiMessage(tr("Cannot delete \"%1\"").arg(selected_item->title()),
|
||||
tr("This item cannot be deleted, because it does not support it\nor this functionality is not implemented yet."),
|
||||
QSystemTrayIcon::Critical,
|
||||
qApp->mainForm(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
// Changes are done, unlock the update master lock.
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "gui/feedsview.h"
|
||||
#include "services/standard/gui/formstandardcategorydetails.h"
|
||||
#include "services/standard/standardserviceroot.h"
|
||||
#include "services/standard/standardfeed.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QSqlQuery>
|
||||
|
@ -131,7 +132,7 @@ QVariant StandardCategory::data(int column, int role) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool StandardCategory::editViaDialog() {
|
||||
bool StandardCategory::editViaGui() {
|
||||
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(serviceRoot(), qApp->mainForm());
|
||||
|
||||
form_pointer.data()->exec(this, NULL);
|
||||
|
@ -139,12 +140,21 @@ bool StandardCategory::editViaDialog() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StandardCategory::deleteViaGui() {
|
||||
return removeItself();
|
||||
}
|
||||
|
||||
bool StandardCategory::removeItself() {
|
||||
bool children_removed = true;
|
||||
|
||||
// Remove all child items (feeds, categories.)
|
||||
foreach (RootItem *child, m_childItems) {
|
||||
children_removed &= child->removeItself();
|
||||
if (child->kind() == RootItemKind::Category) {
|
||||
children_removed &= static_cast<StandardCategory*>(child)->removeItself();
|
||||
}
|
||||
else if (child->kind() == RootItemKind::Feed) {
|
||||
children_removed &= static_cast<StandardFeed*>(child)->removeItself();
|
||||
}
|
||||
}
|
||||
|
||||
if (children_removed) {
|
||||
|
|
|
@ -53,7 +53,8 @@ class StandardCategory : public Category {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool editViaDialog();
|
||||
bool editViaGui();
|
||||
bool deleteViaGui();
|
||||
|
||||
// Removes category and all its children from persistent
|
||||
// database.
|
||||
|
|
|
@ -103,7 +103,7 @@ StandardServiceRoot *StandardFeed::serviceRoot() {
|
|||
return static_cast<StandardServiceRoot*>(getParentServiceRoot());
|
||||
}
|
||||
|
||||
bool StandardFeed::editViaDialog() {
|
||||
bool StandardFeed::editViaGui() {
|
||||
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(serviceRoot(), qApp->mainForm());
|
||||
|
||||
form_pointer.data()->exec(this, NULL);
|
||||
|
@ -111,6 +111,10 @@ bool StandardFeed::editViaDialog() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StandardFeed::deleteViaGui() {
|
||||
return removeItself();
|
||||
}
|
||||
|
||||
QList<Message> StandardFeed::undeletedMessages() const {
|
||||
QList<Message> messages;
|
||||
|
||||
|
|
|
@ -69,7 +69,8 @@ class StandardFeed : public Feed {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool editViaDialog();
|
||||
bool editViaGui();
|
||||
bool deleteViaGui();
|
||||
|
||||
QList<Message> undeletedMessages() const;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ TtRssServiceRoot::TtRssServiceRoot(FeedsModel *feeds_model, RootItem *parent) :
|
|||
TtRssServiceRoot::~TtRssServiceRoot() {
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::editViaDialog() {
|
||||
bool TtRssServiceRoot::editViaGui() {
|
||||
// TODO: zobrazit custom edit dialog pro ttrss
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class TtRssServiceRoot : public ServiceRoot {
|
|||
|
||||
bool canBeEdited();
|
||||
bool canBeDeleted();
|
||||
bool editViaDialog();
|
||||
bool editViaGui();
|
||||
QVariant data(int column, int role) const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue