aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Fabio Bas2011-01-03 01:40:30 +0000
committerGravatar Fabio Bas2011-01-03 01:40:30 +0000
commitc95fb7ebc950f4302837cceac7152a2e2ed498b3 (patch)
tree0c1a9b365ca7536f175cb05c6eed9e40e7f1e37a /src/modules
parentfix for a crash in /exec when the magic parameter is set and the callback is ... (diff)
downloadKVIrc-c95fb7ebc950f4302837cceac7152a2e2ed498b3.tar.gz
KVIrc-c95fb7ebc950f4302837cceac7152a2e2ed498b3.tar.bz2
KVIrc-c95fb7ebc950f4302837cceac7152a2e2ed498b3.zip
Implemented #1022
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5290 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/channelsjoin/ChannelsJoinDialog.cpp120
-rw-r--r--src/modules/channelsjoin/ChannelsJoinDialog.h81
2 files changed, 149 insertions, 52 deletions
diff --git a/src/modules/channelsjoin/ChannelsJoinDialog.cpp b/src/modules/channelsjoin/ChannelsJoinDialog.cpp
index 65e307028..91703aeae 100644
--- a/src/modules/channelsjoin/ChannelsJoinDialog.cpp
+++ b/src/modules/channelsjoin/ChannelsJoinDialog.cpp
@@ -37,18 +37,18 @@
#include "KviKvsScript.h"
#include "KviTalGroupBox.h"
-#include <QTreeWidget>
#include <QLabel>
#include <QLineEdit>
#include <QLayout>
#include <QPushButton>
#include <QEvent>
#include <QCloseEvent>
+#include <QMouseEvent>
#include <QHeaderView>
#include <QCheckBox>
-extern ChannelsJoinDialog * g_pChannelsWindow;
+extern ChannelsJoinDialog * g_pChannelsWindow;
extern QRect g_rectChannelsJoinGeometry;
// KviApplication.cpp
extern KVIRC_API KviRegisteredChannelDataBase * g_pRegisteredChannelDataBase;
@@ -65,12 +65,11 @@ ChannelsJoinDialog::ChannelsJoinDialog(QWidget * par, const char * name)
QGridLayout * g = new QGridLayout(this);
- m_pTreeWidget = new QTreeWidget(this);
+ m_pTreeWidget = new ChannelsJoinDialogTreeWidget(this);
m_pTreeWidget->setHeaderLabel(__tr2qs("Channel"));
m_pTreeWidget->setRootIsDecorated(true);
m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
g->addWidget(m_pTreeWidget,0,0,1,2);
- connect(m_pTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(itemClicked(QTreeWidgetItem *,int)));
connect(m_pTreeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)),this,SLOT(itemDoubleClicked(QTreeWidgetItem *,int)));
@@ -167,7 +166,7 @@ void ChannelsJoinDialog::fillListView()
// Registered channels go first
- QTreeWidgetItem * par = new QTreeWidgetItem(m_pTreeWidget);
+ QTreeWidgetItem * par = new QTreeWidgetItem(m_pTreeWidget, HeaderItem);
par->setText(0,__tr2qs("Registered Channels"));
par->setExpanded(true);
@@ -176,13 +175,13 @@ void ChannelsJoinDialog::fillListView()
{
for(QHash<QString,KviRegisteredChannelList *>::Iterator it = d->begin();it != d->end();++it)
{
- QTreeWidgetItem * chld = new QTreeWidgetItem(par);
+ QTreeWidgetItem * chld = new QTreeWidgetItem(par, RegisteredChannelItem);
chld->setText(0,it.key());
chld->setIcon(0,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));
}
}
- par = new QTreeWidgetItem(m_pTreeWidget);
+ par = new QTreeWidgetItem(m_pTreeWidget, HeaderItem);
par->setText(0,__tr2qs("Recent Channels"));
par->setExpanded(true);
@@ -199,13 +198,13 @@ void ChannelsJoinDialog::fillListView()
{
bGotChanOnCurrentNetwork = true;
- par = new QTreeWidgetItem(par);
+ par = new QTreeWidgetItem(par, HeaderItem);
par->setText(0,__tr2qs("Current Network"));
par->setExpanded(true);
for(QStringList::Iterator it = pList->begin(); it != pList->end(); ++it)
{
- chld = new QTreeWidgetItem(par);
+ chld = new QTreeWidgetItem(par, RecentChannelItem);
chld->setText(0,*it);
chld->setIcon(0,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));
}
@@ -217,7 +216,7 @@ void ChannelsJoinDialog::fillListView()
if(!pDict)
return;
- par = new QTreeWidgetItem(par);
+ par = new QTreeWidgetItem(par, HeaderItem);
par->setText(0,__tr2qs("All Networks"));
if(!bGotChanOnCurrentNetwork)
@@ -233,36 +232,66 @@ void ChannelsJoinDialog::fillListView()
if(hNoDuplicates.contains(chan.toLower()))
continue;
hNoDuplicates.insert(chan.toLower(),1);
- chld = new QTreeWidgetItem(par);
+ chld = new QTreeWidgetItem(par, RecentChannelItem);
chld->setText(0,chan);
chld->setIcon(0,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));
}
}
}
-void ChannelsJoinDialog::itemClicked(QTreeWidgetItem * it, int)
+void ChannelsJoinDialogTreeWidget::mousePressEvent(QMouseEvent *e)
{
- if(!it)
+ QTreeWidgetItem * it = itemAt(e->pos());
+ ChannelsJoinDialog *pDialog = (ChannelsJoinDialog*) parentWidget();
+ if(!it || !pDialog)
return;
- if(it->childCount())
+
+ setCurrentItem(it);
+
+ if(it->type() == ChannelsJoinDialog::HeaderItem)
return;
- QString szTmp = it->text(0);
- m_pChannelEdit->setText(szTmp);
- enableJoin();
+ if(e->button() & Qt::RightButton)
+ {
+ if(!m_pJoinPopup)
+ {
+ m_pJoinPopup = new KviTalPopupMenu(this);
+ m_pJoinPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_JOIN)),__tr2qs("Join"),pDialog,SLOT(joinClicked()));
+ m_pJoinPopup->insertItem(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD)),__tr2qs("Delete"),pDialog,SLOT(deleteClicked()));
+ }
+
+ m_pJoinPopup->popup(QCursor::pos());
+ } else {
+ pDialog->itemSelected();
+ }
+}
+
+void ChannelsJoinDialogTreeWidget::mouseDoubleClickEvent(QMouseEvent *e)
+{
+ QTreeWidgetItem * it = itemAt(e->pos());
+ ChannelsJoinDialog *pDialog = (ChannelsJoinDialog*) parentWidget();
+ if(!it || !pDialog || !(e->button() & Qt::LeftButton))
+ return;
+
+ if(it->type() == ChannelsJoinDialog::HeaderItem)
+ return;
+
+ setCurrentItem(it);
+ pDialog->itemSelected();
+ pDialog->joinClicked();
}
-void ChannelsJoinDialog::itemDoubleClicked(QTreeWidgetItem * it, int)
+void ChannelsJoinDialog::itemSelected()
{
+ QTreeWidgetItem * it = m_pTreeWidget->currentItem();
if(!it)
return;
- if(it->childCount())
+ if(it->type() == HeaderItem)
return;
QString szTmp = it->text(0);
m_pChannelEdit->setText(szTmp);
enableJoin();
- joinClicked();
}
void ChannelsJoinDialog::editTextChanged(const QString &)
@@ -296,6 +325,49 @@ void ChannelsJoinDialog::cancelClicked()
delete this;
}
+void ChannelsJoinDialog::deleteClicked()
+{
+ //FIXME this actually removes channel without matching their network,
+ // since the whole ChannelsJoinDialog does not consider networks
+ QTreeWidgetItem * it = m_pTreeWidget->currentItem();
+ if(!it)
+ return;
+ if(it->type() == HeaderItem)
+ return;
+
+ QString szChan = it->text(0);
+ switch(it->type())
+ {
+ case RegisteredChannelItem:
+ {
+ KviRegisteredChannel * ch = g_pRegisteredChannelDataBase->find(szChan,QString("*"));
+ if(ch)
+ g_pRegisteredChannelDataBase->remove(ch);
+ delete it;
+ break;
+ }
+ case RecentChannelItem:
+ {
+ KviPointerHashTable<QString,QStringList> * pDict = g_pApp->recentChannels();
+ if(!pDict)
+ return;
+ for(QStringList * pChans = pDict->first();pChans;pChans = pDict->next())
+ {
+ for(QStringList::Iterator item = pChans->begin(); item != pChans->end(); ++item)
+ {
+ if(*item==szChan)
+ {
+ pChans->removeAll(szChan);
+ delete it;
+ return;
+ }
+ }
+ }
+ break;
+ }
+ }
+}
+
void ChannelsJoinDialog::joinClicked()
{
QString szPass = m_pPass->text();
@@ -387,14 +459,6 @@ void ChannelsJoinDialog::namesClicked()
if(!tmp.isEmpty())doCmd("raw names", tmp.ptr());
}
-void ChannelsJoinDialog::itemDoubleClicked(KviTalListBoxItem * it)
-{
- if (it == 0)return;
- KviCString tmp = it->text();
- doCmd("join", tmp.ptr());
-// if(KVI_OPTION_BOOL(KviOption_boolCloseChannelsJoinAfterJoin))
-// g_pApp->collectGarbage(this);
-}
*/
void ChannelsJoinDialog::editReturnPressed()
diff --git a/src/modules/channelsjoin/ChannelsJoinDialog.h b/src/modules/channelsjoin/ChannelsJoinDialog.h
index b4b64145e..45914c23a 100644
--- a/src/modules/channelsjoin/ChannelsJoinDialog.h
+++ b/src/modules/channelsjoin/ChannelsJoinDialog.h
@@ -32,8 +32,9 @@
#include "KviWindow.h"
#include "KviCString.h"
-#include <QTreeWidget>
+#include "KviTalPopupMenu.h"
+#include <QTreeWidget>
#include <QDialog>
class QCheckBox;
@@ -43,12 +44,42 @@ class KviConsoleWindow;
class KviTalGroupBox;
/**
+* \class ChannelsJoinDialogTreeWidget
+* \brief Channels join window tree widget
+*/
+class KVIRC_API ChannelsJoinDialogTreeWidget : public QTreeWidget
+{
+ Q_OBJECT
+public:
+ ChannelsJoinDialogTreeWidget(QWidget * par)
+ :QTreeWidget(par), m_pJoinPopup(0)
+ {
+ };
+
+ ~ChannelsJoinDialogTreeWidget()
+ {
+ if(m_pJoinPopup)
+ delete m_pJoinPopup;
+ };
+protected:
+ KviTalPopupMenu * m_pJoinPopup;
+ /**
+ * \brief Called when the user clicks on the list
+ * \param e mouse event descriptor
+ * \return void
+ */
+ virtual void mousePressEvent(QMouseEvent * e);
+ virtual void mouseDoubleClickEvent(QMouseEvent * e);
+};
+
+/**
* \class ChannelsJoinDialog
* \brief Channels join window class
*/
class ChannelsJoinDialog : public QDialog
{
Q_OBJECT
+ friend class ChannelsJoinDialogTreeWidget;
public:
/**
* \brief Constructs the channels join window
@@ -62,17 +93,19 @@ public:
* \brief Destroys the channels join window
*/
~ChannelsJoinDialog();
+
protected:
- QLineEdit * m_pChannelEdit;
- QTreeWidget * m_pTreeWidget;
- KviTalGroupBox * m_pGroupBox;
- QLineEdit * m_pPass;
- QCheckBox * m_pShowAtStartupCheck;
- QCheckBox * m_pCloseAfterJoinCheck;
- QPushButton * m_pJoinButton;
- QPushButton * m_pRegButton;
- QPushButton * m_pClearButton;
- KviConsoleWindow * m_pConsole;
+ enum ItemTypes { HeaderItem, RecentChannelItem, RegisteredChannelItem };
+ QLineEdit * m_pChannelEdit;
+ ChannelsJoinDialogTreeWidget * m_pTreeWidget;
+ KviTalGroupBox * m_pGroupBox;
+ QLineEdit * m_pPass;
+ QCheckBox * m_pShowAtStartupCheck;
+ QCheckBox * m_pCloseAfterJoinCheck;
+ QPushButton * m_pJoinButton;
+ QPushButton * m_pRegButton;
+ QPushButton * m_pClearButton;
+ KviConsoleWindow * m_pConsole;
public:
virtual void closeEvent(QCloseEvent * e);
@@ -94,26 +127,18 @@ public:
* \return void
*/
void setConsole(KviConsoleWindow * pConsole);
-protected slots:
- /**
- * \brief Called when the text changes
- * \return void
- */
- void editTextChanged(const QString &);
/**
- * \brief Called when an item is clicked
- * \param it The item clicked
+ * \brief Called when the user choose an item from the list
* \return void
*/
- void itemClicked(QTreeWidgetItem * it, int);
-
+ void itemSelected();
+protected slots:
/**
- * \brief Called when an item is double-clicked
- * \param it The item clicked
+ * \brief Called when the text changes
* \return void
*/
- void itemDoubleClicked(QTreeWidgetItem * it, int);
+ void editTextChanged(const QString &);
/**
* \brief Called when the return is pressed
@@ -140,6 +165,14 @@ protected slots:
void joinClicked();
/**
+ * \brief Called when the delete button is pressed
+ *
+ * It deletes the selected channel
+ * \return void
+ */
+ void deleteClicked();
+
+ /**
* \brief Called when the register button is pressed
*
* It registers the selected channel in the database