Browse Source

Added right click menu for the rss download rules list

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
c47dbfb1f5
  1. 50
      src/rss/automatedrssdownloader.cpp
  2. 4
      src/rss/automatedrssdownloader.h
  3. 6
      src/rss/automatedrssdownloader.ui

50
src/rss/automatedrssdownloader.cpp

@ -32,6 +32,8 @@ @@ -32,6 +32,8 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QDebug>
#include <QMenu>
#include <QCursor>
#include "automatedrssdownloader.h"
#include "ui_automatedrssdownloader.h"
@ -46,6 +48,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) : @@ -46,6 +48,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent) :
{
ui->setupUi(this);
ui->listRules->setSortingEnabled(true);
connect(ui->listRules, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayRulesListMenu(const QPoint&)));
m_ruleList = RssDownloadRuleList::instance();
initLabelCombobox();
loadFeedList();
@ -296,3 +299,50 @@ void AutomatedRssDownloader::on_importBtn_clicked() @@ -296,3 +299,50 @@ void AutomatedRssDownloader::on_importBtn_clicked()
// Reload the rule list
loadRulesList();
}
void AutomatedRssDownloader::displayRulesListMenu(const QPoint &pos)
{
Q_UNUSED(pos);
QMenu menu;
QAction *addAct = menu.addAction(QIcon(":/Icons/oxygen/list-add.png"), tr("Add new rule..."));
QAction *delAct = 0;
QAction *renameAct = 0;
if(!ui->listRules->selectedItems().isEmpty()) {
delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), tr("Delete rule"));
menu.addSeparator();
renameAct = menu.addAction(QIcon(":/Icons/oxygen/edit_clear.png"), tr("Rename rule..."));
}
QAction *act = menu.exec(QCursor::pos());
if(!act) return;
if(act == addAct) {
on_addRuleBtn_clicked();
return;
}
if(act == delAct) {
on_removeRuleBtn_clicked();
return;
}
if(act == renameAct) {
renameSelectedRule();
return;
}
}
void AutomatedRssDownloader::renameSelectedRule()
{
QListWidgetItem *item = ui->listRules->currentItem();
if(!item) return;
forever {
QString new_name = QInputDialog::getText(this, tr("Rule renaming"), tr("Please type the new rule name"), QLineEdit::Normal, item->text());
new_name = new_name.trimmed();
if(new_name.isEmpty()) return;
if(m_ruleList->ruleNames().contains(new_name, Qt::CaseInsensitive)) {
QMessageBox::warning(this, tr("Rule name conflict"), tr("A rule with this name already exists, please choose another name."));
} else {
// Rename the rule
m_ruleList->renameRule(item->text(), new_name);
item->setText(new_name);
return;
}
}
}

4
src/rss/automatedrssdownloader.h

@ -60,13 +60,13 @@ protected slots: @@ -60,13 +60,13 @@ protected slots:
void updateFeedList(QListWidgetItem* current, QListWidgetItem* previous);
private slots:
void displayRulesListMenu(const QPoint& pos);
void on_addRuleBtn_clicked();
void on_removeRuleBtn_clicked();
void on_browseSP_clicked();
void on_exportBtn_clicked();
void on_importBtn_clicked();
void renameSelectedRule();
private:
RssDownloadRule getCurrentRule() const;

6
src/rss/automatedrssdownloader.ui

@ -112,7 +112,11 @@ @@ -112,7 +112,11 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="listRules"/>
<widget class="QListWidget" name="listRules">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</item>

Loading…
Cancel
Save