Some work on deleting, fix for external browser.
This commit is contained in:
parent
01a41de45b
commit
e1e8f134e0
@ -133,42 +133,26 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
|
||||
return parent_item->childCount();
|
||||
}
|
||||
|
||||
// TODO: přepsat tudle metodu,
|
||||
// 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;
|
||||
bool FeedsModel::removeItem(const QModelIndex &index) {
|
||||
if (index.isValid()) {
|
||||
QModelIndex parent_index = index.parent();
|
||||
FeedsModelRootItem *deleting_item = itemForIndex(index);
|
||||
FeedsModelRootItem *parent_item = itemForIndex(parent_index);
|
||||
|
||||
// Collect all items lying on given indexes.
|
||||
foreach (const QModelIndex &index, indexes) {
|
||||
FeedsModelRootItem *item = itemForIndex(index);
|
||||
beginRemoveRows(parent_index, index.row(), index.row());
|
||||
|
||||
if (item->kind() != FeedsModelRootItem::RootItem) {
|
||||
items << item;
|
||||
if (deleting_item->removeItself() &&
|
||||
parent_item->removeChild(deleting_item)) {
|
||||
// Free deleted item from the memory
|
||||
delete deleting_item;
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove given items from the model.
|
||||
foreach (FeedsModelRootItem *item, items) {
|
||||
QModelIndex index = indexForItem(item);
|
||||
|
||||
if (index.isValid()) {
|
||||
QModelIndex parent_index = index.parent();
|
||||
FeedsModelRootItem *parent_item = itemForIndex(parent_index);
|
||||
|
||||
beginRemoveRows(parent_index, index.row(), index.row());
|
||||
if (item->removeItself() || parent_item->removeChild(index.row())) {
|
||||
items_for_deletion << item;
|
||||
}
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
qDeleteAll(items_for_deletion);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed*> &feeds) {
|
||||
|
@ -46,7 +46,7 @@ class FeedsModel : public QAbstractItemModel {
|
||||
}
|
||||
|
||||
// Feed/category manipulators.
|
||||
bool removeItems(const QModelIndexList &indexes);
|
||||
bool removeItem(const QModelIndex &index);
|
||||
|
||||
// Returns (undeleted) messages for given feeds.
|
||||
QList<Message> messagesForFeeds(const QList<FeedsModelFeed*> &feeds);
|
||||
|
@ -46,6 +46,10 @@ int FeedsModelRootItem::countOfAllMessages() const {
|
||||
return total_count;
|
||||
}
|
||||
|
||||
bool FeedsModelRootItem::removeChild(FeedsModelRootItem *child) {
|
||||
return m_childItems.removeOne(child);
|
||||
}
|
||||
|
||||
int FeedsModelRootItem::countOfUnreadMessages() const {
|
||||
int total_count = 0;
|
||||
|
||||
|
@ -72,6 +72,37 @@ class FeedsModelRootItem {
|
||||
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.
|
||||
// NOTE: Children are NOT freed from the memory.
|
||||
inline void clearChildren() {
|
||||
@ -81,6 +112,7 @@ class FeedsModelRootItem {
|
||||
// Removes particular child at given index.
|
||||
// NOTE: Child is NOT freed from the memory.
|
||||
bool removeChild(int index);
|
||||
bool removeChild(FeedsModelRootItem *child);
|
||||
|
||||
inline Kind kind() const {
|
||||
return m_kind;
|
||||
|
@ -223,8 +223,8 @@ void FeedMessageViewer::createConnections() {
|
||||
SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem()));
|
||||
connect(FormMain::instance()->m_ui->m_actionViewSelectedItemsNewspaperMode,
|
||||
SIGNAL(triggered()), m_feedsView, SLOT(openSelectedFeedsInNewspaperMode()));
|
||||
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedsCategories,
|
||||
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItems()));
|
||||
connect(FormMain::instance()->m_ui->m_actionDeleteSelectedFeedCategory,
|
||||
SIGNAL(triggered()), m_feedsView, SLOT(deleteSelectedItem()));
|
||||
}
|
||||
|
||||
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_actionAddNewFeed);
|
||||
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_actionMarkFeedsAsUnread);
|
||||
m_toolBar->addAction(FormMain::instance()->m_ui->m_actionClearFeeds);
|
||||
|
@ -103,23 +103,8 @@ void FeedsView::editSelectedItem() {
|
||||
|
||||
}
|
||||
|
||||
void FeedsView::deleteSelectedItems() {
|
||||
QModelIndexList selection = selectionModel()->selectedRows();
|
||||
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::deleteSelectedItem() {
|
||||
m_sourceModel->removeItem(m_proxyModel->mapToSource(currentIndex()));
|
||||
}
|
||||
|
||||
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||
@ -233,7 +218,7 @@ void FeedsView::setupAppearance() {
|
||||
setIndentation(10);
|
||||
setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||
setAllColumnsShowFocus(true);
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
setRootIsDecorated(false);
|
||||
|
||||
// Sort in ascending order, that is categories are
|
||||
|
@ -71,7 +71,7 @@ class FeedsView : public QTreeView {
|
||||
// Category operators.
|
||||
void addNewCategory();
|
||||
void editSelectedItem();
|
||||
void deleteSelectedItems();
|
||||
void deleteSelectedItem();
|
||||
|
||||
// Reloads counts for selected feeds.
|
||||
void updateCountsOfSelectedFeeds(bool update_total_too = true);
|
||||
|
@ -86,7 +86,7 @@ QList<QAction*> FormMain::allActions() {
|
||||
m_ui->m_actionUpdateAllFeeds <<
|
||||
m_ui->m_actionUpdateSelectedFeedsCategories <<
|
||||
m_ui->m_actionEditSelectedFeedCategory <<
|
||||
m_ui->m_actionDeleteSelectedFeedsCategories;
|
||||
m_ui->m_actionDeleteSelectedFeedCategory;
|
||||
|
||||
return actions;
|
||||
}
|
||||
@ -222,7 +222,7 @@ void FormMain::setupIcons() {
|
||||
m_ui->m_actionUpdateAllFeeds->setIcon(IconThemeFactory::instance()->fromTheme("document-save-as"));
|
||||
m_ui->m_actionUpdateSelectedFeedsCategories->setIcon(IconThemeFactory::instance()->fromTheme("document-save"));
|
||||
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_actionAddNewCategory->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
||||
m_ui->m_actionAddNewFeed->setIcon(IconThemeFactory::instance()->fromTheme("document-new"));
|
||||
|
@ -15,16 +15,7 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -48,7 +39,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>979</width>
|
||||
<height>21</height>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="m_menuFile">
|
||||
@ -100,7 +91,7 @@
|
||||
<addaction name="m_actionAddNewFeed"/>
|
||||
<addaction name="m_actionAddNewCategory"/>
|
||||
<addaction name="m_actionEditSelectedFeedCategory"/>
|
||||
<addaction name="m_actionDeleteSelectedFeedsCategories"/>
|
||||
<addaction name="m_actionDeleteSelectedFeedCategory"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="m_actionViewSelectedItemsNewspaperMode"/>
|
||||
<addaction name="m_actionMarkAllFeedsRead"/>
|
||||
@ -251,12 +242,12 @@
|
||||
<string>Edit selected feed/category.</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="m_actionDeleteSelectedFeedsCategories">
|
||||
<action name="m_actionDeleteSelectedFeedCategory">
|
||||
<property name="text">
|
||||
<string>&Delete selected feeds/categories</string>
|
||||
<string>&Delete selected feed/category</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Delete selected feeds/categories.</string>
|
||||
<string>Delete selected feed/category.</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="m_actionMarkSelectedMessagesAsRead">
|
||||
|
@ -229,7 +229,13 @@ void MessagesView::openSelectedSourceArticlesExternally() {
|
||||
|
||||
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
|
||||
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