commit 3614141a6e94ea1820dd731f2bb37f33371a4fcb Author: Justin Karneges Date: Thu Aug 6 20:45:40 2009 -0700 020-psi-muc-kickban-reasons.diff from psi+, with adjustment diff --git a/options/default.xml b/options/default.xml index 988589e..74021f2 100644 --- a/options/default.xml +++ b/options/default.xml @@ -51,6 +51,7 @@ 10 + true diff --git a/src/gcuserview.cpp b/src/gcuserview.cpp index 810feb2..8962425 100644 --- a/src/gcuserview.cpp +++ b/src/gcuserview.cpp @@ -335,10 +335,34 @@ void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos, pm->insertItem(IconsetFactory::icon("psi/sendMessage").icon(), tr("Send &Message"), 0); pm->insertItem(IconsetFactory::icon("psi/start-chat").icon(), tr("Open &Chat Window"), 1); pm->insertSeparator(); - pm->insertItem(tr("&Kick"),10); - pm->setItemEnabled(10, MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem())); - pm->insertItem(tr("&Ban"),11); - pm->setItemEnabled(11, MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem())); + + // Kick and Ban submenus + QStringList reasons = PsiOptions::instance()->getOption("options.muc.reasons").toStringList(); + int cntReasons=reasons.count(); + if (cntReasons>99) cntReasons=99; // Only first 99 reasons + + Q3PopupMenu *kickMenu = new Q3PopupMenu(pm); + kickMenu->insertItem(tr("No reason"),10); + kickMenu->insertItem(tr("Custom reason"),100); + kickMenu->insertSeparator(); + bool canKick=MUCManager::canKick(c->s.mucItem(),lvi->s.mucItem()); + for (int i=0; iinsertItem(reasons[i], 101+i); + kickMenu->setEnabled(canKick); + + Q3PopupMenu *banMenu = new Q3PopupMenu(pm); + banMenu->insertItem(tr("No reason"),11); + banMenu->insertItem(tr("Custom reason"),200); + banMenu->insertSeparator(); + bool canBan=MUCManager::canBan(c->s.mucItem(),lvi->s.mucItem()); + for (int i=0; iinsertItem(reasons[i], 201+i); + banMenu->setEnabled(canBan); + + pm->insertItem(tr("&Kick"), kickMenu); + pm->setItemEnabled(10, canKick); + pm->insertItem(tr("&Ban"), banMenu); + pm->setItemEnabled(11, canBan); Q3PopupMenu* rm = new Q3PopupMenu(pm); rm->insertItem(tr("Visitor"),12); @@ -372,7 +396,7 @@ void GCUserView::qlv_contextMenuRequested(Q3ListViewItem *i, const QPoint &pos, pm->insertItem(tr("Check &Status"), 2); pm->insertItem(IconsetFactory::icon("psi/vCard").icon(), tr("User &Info"), 3); int x = pm->exec(pos); - bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x); + bool enabled = pm->isItemEnabled(x) || rm->isItemEnabled(x) || kickMenu->isItemEnabled(x) || banMenu->isItemEnabled(x); delete pm; if(x == -1 || !enabled || lvi.isNull()) diff --git a/src/groupchatdlg.cpp b/src/groupchatdlg.cpp index 1397af3..baed25b 100644 --- a/src/groupchatdlg.cpp +++ b/src/groupchatdlg.cpp @@ -76,6 +76,7 @@ #include "psicontactlist.h" #include "accountlabel.h" #include "gcuserview.h" +#include "mucreasonseditor.h" #include "mcmdmanager.h" #include "mcmdsimplesite.h" @@ -1712,6 +1713,32 @@ void GCMainDlg::lv_action(const QString &nick, const Status &s, int x) if (contact->s.mucItem().role() != MUCItem::Moderator) d->mucManager->setRole(nick, MUCItem::Moderator); } + else if(x >= 100 && x<300) { + // Kick || Ban with reason + QString reason; + QStringList reasons = PsiOptions::instance()->getOption("options.muc.reasons").toStringList(); + if (x==100 || x==200) { + // Show custom reason dialog + MUCReasonsEditor *editor=new MUCReasonsEditor(this); + if (editor->exec()) + reason=editor->reason(); + delete editor; + } else { + int idx = (x<200) ? x-101 : x-201; + if (idxmucManager->kick(nick, reason); + else { + GCUserViewItem *contact = (GCUserViewItem*) ui_.lv_users->findEntry(nick); + if (!contact) return; + d->mucManager->ban(contact->s.mucItem().jid(), reason); + } + } + + } /*else if(x == 15) { GCUserViewItem *contact = (GCUserViewItem*) ui_.lv_users->findEntry(nick); if (contact->s.mucItem().affiliation() != MUCItem::NoAffiliation) diff --git a/src/mucreasonseditor.cpp b/src/mucreasonseditor.cpp new file mode 100644 index 0000000..54117ba --- /dev/null +++ b/src/mucreasonseditor.cpp @@ -0,0 +1,44 @@ +#include "mucreasonseditor.h" +#include "common.h" +#include "psioptions.h" + + +MUCReasonsEditor::MUCReasonsEditor(QWidget* parent) + : QDialog(parent) +{ + ui_.setupUi(this); + ui_.lstReasons->addItems(PsiOptions::instance()->getOption("options.muc.reasons").toStringList()); +} + +MUCReasonsEditor::~MUCReasonsEditor() +{ +} + +void MUCReasonsEditor::accept() +{ + QStringList reasons; + int cnt=ui_.lstReasons->count(); + for (int i=0; iitem(i)->text()); + PsiOptions::instance()->setOption("options.muc.reasons", reasons); + reason_=ui_.txtReason->text(); + QDialog::accept(); +} + +void MUCReasonsEditor::on_btnAdd_clicked() +{ + reason_=ui_.txtReason->text().trimmed(); + if (reason_.isEmpty()) + return; + ui_.lstReasons->addItem(reason_); +} + +void MUCReasonsEditor::on_btnRemove_clicked() +{ + int idx=ui_.lstReasons->currentRow(); + if (idx>=0) { + QListWidgetItem *item =ui_.lstReasons->takeItem(idx); + if (item) delete item; + } +} + diff --git a/src/mucreasonseditor.h b/src/mucreasonseditor.h new file mode 100644 index 0000000..765fb2e --- /dev/null +++ b/src/mucreasonseditor.h @@ -0,0 +1,25 @@ +#ifndef MUCREASONSEDITOR_H +#define MUCREASONSEDITOR_H + +#include + +#include "ui_mucreasonseditor.h" + +class MUCReasonsEditor: public QDialog +{ + Q_OBJECT +public: + MUCReasonsEditor(QWidget* parent = 0); + ~MUCReasonsEditor(); + QString reason() const { return reason_; } +private: + Ui::MUCReasonsEditor ui_; + QString reason_; +private slots: + void on_btnAdd_clicked(); + void on_btnRemove_clicked(); +protected slots: + void accept(); +}; + +#endif diff --git a/src/mucreasonseditor.ui b/src/mucreasonseditor.ui new file mode 100644 index 0000000..b1d9b8a --- /dev/null +++ b/src/mucreasonseditor.ui @@ -0,0 +1,151 @@ + + MUCReasonsEditor + + + + 0 + 0 + 400 + 300 + + + + Reason editor + + + + 9 + + + 6 + + + + + Reasons + + + + 9 + + + 6 + + + + + + + + + + + + + + + 0 + + + 6 + + + + + Add + + + + + + + Remove + + + + + + + + + + + + 0 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ok + + + false + + + true + + + + + + + Cancel + + + + + + + + + + + btnOk + clicked() + MUCReasonsEditor + accept() + + + 265 + 271 + + + -2 + 287 + + + + + btnCancel + clicked() + MUCReasonsEditor + reject() + + + 341 + 283 + + + 81 + 272 + + + + + diff --git a/src/src.pri b/src/src.pri index 2487038..1562bab 100644 --- a/src/src.pri +++ b/src/src.pri @@ -190,6 +190,7 @@ HEADERS += \ $$PWD/mucaffiliationsmodel.h \ $$PWD/mucaffiliationsproxymodel.h \ $$PWD/mucaffiliationsview.h \ + $$PWD/mucreasonseditor.h \ $$PWD/rosteritemexchangetask.h \ $$PWD/mood.h \ $$PWD/moodcatalog.h \ @@ -308,6 +309,7 @@ SOURCES += \ $$PWD/mucaffiliationsmodel.cpp \ $$PWD/mucaffiliationsproxymodel.cpp \ $$PWD/mucaffiliationsview.cpp \ + $$PWD/mucreasonseditor.cpp \ $$PWD/rosteritemexchangetask.cpp \ $$PWD/mood.cpp \ $$PWD/moodcatalog.cpp \ @@ -411,6 +413,7 @@ INTERFACES += \ $$PWD/optioneditor.ui \ $$PWD/passphrase.ui \ $$PWD/mucconfig.ui \ + $$PWD/mucreasonseditor.ui \ $$PWD/xmlconsole.ui \ $$PWD/disco.ui \ $$PWD/tip.ui \