Some work on deleting, fix for external browser.
This commit is contained in:
parent
01a41de45b
commit
e1e8f134e0
@ -133,44 +133,28 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
|
|||||||
return parent_item->childCount();
|
return parent_item->childCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: přepsat tudle metodu,
|
bool FeedsModel::removeItem(const QModelIndex &index) {
|
||||||
// vim ze to zhruba funguje ale je potreba pridat taky
|
|
||||||
// vymazani feedu/kategorie z SQL (pridat metodu do FeedsModelRootItem
|
|
||||||
// kterou si podedi)
|
|
||||||
bool FeedsModel::removeItems(const QModelIndexList &indexes) {
|
|
||||||
QList<FeedsModelRootItem*> items;
|
|
||||||
QList<FeedsModelRootItem*> items_for_deletion;
|
|
||||||
|
|
||||||
// Collect all items lying on given indexes.
|
|
||||||
foreach (const QModelIndex &index, indexes) {
|
|
||||||
FeedsModelRootItem *item = itemForIndex(index);
|
|
||||||
|
|
||||||
if (item->kind() != FeedsModelRootItem::RootItem) {
|
|
||||||
items << item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove given items from the model.
|
|
||||||
foreach (FeedsModelRootItem *item, items) {
|
|
||||||
QModelIndex index = indexForItem(item);
|
|
||||||
|
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
QModelIndex parent_index = index.parent();
|
QModelIndex parent_index = index.parent();
|
||||||
|
FeedsModelRootItem *deleting_item = itemForIndex(index);
|
||||||
FeedsModelRootItem *parent_item = itemForIndex(parent_index);
|
FeedsModelRootItem *parent_item = itemForIndex(parent_index);
|
||||||
|
|
||||||
beginRemoveRows(parent_index, index.row(), index.row());
|
beginRemoveRows(parent_index, index.row(), index.row());
|
||||||
if (item->removeItself() || parent_item->removeChild(index.row())) {
|
|
||||||
items_for_deletion << item;
|
if (deleting_item->removeItself() &&
|
||||||
}
|
parent_item->removeChild(deleting_item)) {
|
||||||
endRemoveRows();
|
// Free deleted item from the memory
|
||||||
}
|
delete deleting_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDeleteAll(items_for_deletion);
|
endRemoveRows();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed*> &feeds) {
|
QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed*> &feeds) {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Feed/category manipulators.
|
// Feed/category manipulators.
|
||||||
bool removeItems(const QModelIndexList &indexes);
|
bool removeItem(const QModelIndex &index);
|
||||||
|
|
||||||
// Returns (undeleted) messages for given feeds.
|
// Returns (undeleted) messages for given feeds.
|
||||||
QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds);
|
QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds);
|
||||||
|
@ -46,6 +46,10 @@ int FeedsModelRootItem::countOfAllMessages() const {
|
|||||||
return total_count;
|
return total_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsModelRootItem::removeChild(FeedsModelRootItem *child) {
|
||||||
|
return m_childItems.removeOne(child);
|
||||||
|
}
|
||||||
|
|
||||||
int FeedsModelRootItem::countOfUnreadMessages() const {
|
int FeedsModelRootItem::countOfUnreadMessages() const {
|
||||||
int total_count = 0;
|
int total_count = 0;
|
||||||
|
|
||||||
|
@ -72,6 +72,37 @@ class FeedsModelRootItem {
|
|||||||
return m_childItems;
|
return m_childItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks whether this instance is child (can be nested)
|
||||||
|
// if given root item.
|
||||||
|
bool isChild(FeedsModelRootItem *root) {
|
||||||
|
|
||||||
|
while (root->kind() != FeedsModelRootItem::RootItem) {
|
||||||
|
if (root->childItems().contains(this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
root = root->parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
/*
|
||||||
|
parents << root;
|
||||||
|
|
||||||
|
while (!parents.isEmpty()) {
|
||||||
|
foreach (FeedsModelRootItem *root_child, parents.takeFirst()->childItems()) {
|
||||||
|
if (root_child == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (root_child->kind() == FeedsModelRootItem::Category) {
|
||||||
|
parents << root_child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;*/
|
||||||
|
}
|
||||||
|
|
||||||
// Removes all children from this item.
|
// Removes all children from this item.
|
||||||
// NOTE: Children are NOT freed from the memory.
|
// NOTE: Children are NOT freed from the memory.
|
||||||
inline void clearChildren() {
|
inline void clearChildren() {
|
||||||
@ -81,6 +112,7 @@ class FeedsModelRootItem {
|
|||||||
// Removes particular child at given index.
|
// Removes particular child at given index.
|
||||||
// NOTE: Child is NOT freed from the memory.
|
// NOTE: Child is NOT freed from the memory.
|
||||||
bool removeChild(int index);
|
bool removeChild(int index);
|
||||||
|
bool removeChild(FeedsModelRootItem *child);
|
||||||
|
|
||||||
inline Kind kind() const {
|
inline Kind kind() const {
|
||||||
return m_kind;
|
return m_kind;
|
||||||
|
@ -223,8 +223,8 @@ void FeedMessageViewer::createConnections() {
|
|||||||
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
|
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
|
||||||
connect(FormMain::instance()->m_ui->m_actionViewSelectedItemsNewspaperMode,
|
connect(FormMain::instance()->m_ui->m_actionViewSelectedItemsNewspaperMode,
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
||||||
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedsCategories,
|
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedCategory,
|
||||||
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItems()));
|
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::initialize() {
|
void FeedMessageViewer::initialize() {
|
||||||
@ -241,7 +241,7 @@ void FeedMessageViewer::initialize() {
|
|||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionUpdateSelectedFeedsCategories);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionUpdateSelectedFeedsCategories);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionAddNewFeed);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionAddNewFeed);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionEditSelectedFeedCategory);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionEditSelectedFeedCategory);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedsCategories);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedCategory);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionMarkFeedsAsRead);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionMarkFeedsAsRead);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionMarkFeedsAsUnread);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionMarkFeedsAsUnread);
|
||||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionClearFeeds);
|
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionClearFeeds);
|
||||||
|
@ -103,23 +103,8 @@ void FeedsView::editSelectedItem() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::deleteSelectedItems() {
|
void FeedsView::deleteSelectedItem() {
|
||||||
QModelIndexList selection = selectionModel()->selectedRows();
|
m_sourceModel->removeItem(m_proxyModel->mapToSource(currentIndex()));
|
||||||
QModelIndexList mapped_selection = m_proxyModel->mapListToSource(selection);
|
|
||||||
|
|
||||||
//FeedsModelRootItem *parent = m_sourceModel->itemForIndex(mapped_selection.at(0).parent());
|
|
||||||
|
|
||||||
m_sourceModel->removeItems(mapped_selection);
|
|
||||||
|
|
||||||
/*
|
|
||||||
QModelIndex id = m_sourceModel->indexForItem(parent);
|
|
||||||
|
|
||||||
if (id.isValid()) {
|
|
||||||
selectionModel()->clearSelection();
|
|
||||||
selectionModel()->select(m_proxyModel->mapFromSource(id),
|
|
||||||
QItemSelectionModel::Rows |
|
|
||||||
QItemSelectionModel::Select);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||||
@ -233,7 +218,7 @@ void FeedsView::setupAppearance() {
|
|||||||
setIndentation(10);
|
setIndentation(10);
|
||||||
setDragDropMode(QAbstractItemView::NoDragDrop);
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||||
setAllColumnsShowFocus(true);
|
setAllColumnsShowFocus(true);
|
||||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
setRootIsDecorated(false);
|
setRootIsDecorated(false);
|
||||||
|
|
||||||
// Sort in ascending order, that is categories are
|
// Sort in ascending order, that is categories are
|
||||||
|
@ -71,7 +71,7 @@ class FeedsView : public QTreeView {
|
|||||||
// Category operators.
|
// Category operators.
|
||||||
void addNewCategory();
|
void addNewCategory();
|
||||||
void editSelectedItem();
|
void editSelectedItem();
|
||||||
void deleteSelectedItems();
|
void deleteSelectedItem();
|
||||||
|
|
||||||
// Reloads counts for selected feeds.
|
// Reloads counts for selected feeds.
|
||||||
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
||||||
|
@ -86,7 +86,7 @@ QList<QAction*> FormMain::allActions() {
|
|||||||
m_ui->m_actionUpdateAllFeeds <<
|
m_ui->m_actionUpdateAllFeeds <<
|
||||||
m_ui->m_actionUpdateSelectedFeedsCategories <<
|
m_ui->m_actionUpdateSelectedFeedsCategories <<
|
||||||
m_ui->m_actionEditSelectedFeedCategory <<
|
m_ui->m_actionEditSelectedFeedCategory <<
|
||||||
m_ui->m_actionDeleteSelectedFeedsCategories;
|
m_ui->m_actionDeleteSelectedFeedCategory;
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ void FormMain::setupIcons() {
|
|||||||
m_ui->m_actionUpdateAllFeeds->setIcon(IconThemeFactory::instance()->fromTheme("document-save-as"));
|
m_ui->m_actionUpdateAllFeeds->setIcon(IconThemeFactory::instance()->fromTheme("document-save-as"));
|
||||||
m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(IconThemeFactory::instance()->fromTheme("document-save"));
|
m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(IconThemeFactory::instance()->fromTheme("document-save"));
|
||||||
m_ui->m_actionClearFeeds->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-junk"));
|
m_ui->m_actionClearFeeds->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-junk"));
|
||||||
m_ui->m_actionDeleteSelectedFeedsCategories->setIcon(IconThemeFactory::instance()->fromTheme("edit-delete"));
|
m_ui->m_actionDeleteSelectedFeedCategory->setIcon(IconThemeFactory::instance()->fromTheme("edit-delete"));
|
||||||
m_ui->m_actionDeleteSelectedMessages->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-junk"));
|
m_ui->m_actionDeleteSelectedMessages->setIcon(IconThemeFactory::instance()->fromTheme("mail-mark-junk"));
|
||||||
m_ui->m_actionAddNewCategory->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
m_ui->m_actionAddNewCategory->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
||||||
m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
||||||
|
@ -15,16 +15,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="leftMargin">
|
<property name="margin">
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
@ -48,7 +39,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>979</width>
|
<width>979</width>
|
||||||
<height>21</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="m_menuFile">
|
<widget class="QMenu" name="m_menuFile">
|
||||||
@ -100,7 +91,7 @@
|
|||||||
<addaction name="m_actionAddNewFeed"/>
|
<addaction name="m_actionAddNewFeed"/>
|
||||||
<addaction name="m_actionAddNewCategory"/>
|
<addaction name="m_actionAddNewCategory"/>
|
||||||
<addaction name="m_actionEditSelectedFeedCategory"/>
|
<addaction name="m_actionEditSelectedFeedCategory"/>
|
||||||
<addaction name="m_actionDeleteSelectedFeedsCategories"/>
|
<addaction name="m_actionDeleteSelectedFeedCategory"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="m_actionViewSelectedItemsNewspaperMode"/>
|
<addaction name="m_actionViewSelectedItemsNewspaperMode"/>
|
||||||
<addaction name="m_actionMarkAllFeedsRead"/>
|
<addaction name="m_actionMarkAllFeedsRead"/>
|
||||||
@ -251,12 +242,12 @@
|
|||||||
<string>Edit selected feed/category.</string>
|
<string>Edit selected feed/category.</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionDeleteSelectedFeedsCategories">
|
<action name="m_actionDeleteSelectedFeedCategory">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Delete selected feeds/categories</string>
|
<string>&Delete selected feed/category</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Delete selected feeds/categories.</string>
|
<string>Delete selected feed/category.</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionMarkSelectedMessagesAsRead">
|
<action name="m_actionMarkSelectedMessagesAsRead">
|
||||||
|
@ -229,7 +229,13 @@ void MessagesView::openSelectedSourceArticlesExternally() {
|
|||||||
|
|
||||||
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
|
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
|
||||||
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
|
QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
|
||||||
QProcess::execute(browser, QStringList() << arguments.arg(link));
|
|
||||||
|
if (!QProcess::startDetached(browser, QStringList() << arguments.arg(link))) {
|
||||||
|
QMessageBox::critical(this,
|
||||||
|
tr("Problem with starting external web browser"),
|
||||||
|
tr("External web browser could not be started."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user