diff options
| author | 2010-05-29 19:04:31 +0000 | |
|---|---|---|
| committer | 2010-05-29 19:04:31 +0000 | |
| commit | 1165f3409d4e5badf0c9038c8d84b049ab195741 (patch) | |
| tree | 0a30081cd26edcdfe53d5a64819f3754888a17c2 /src/modules/options | |
| parent | More work on the server options widget. (diff) | |
| download | KVIrc-1165f3409d4e5badf0c9038c8d84b049ab195741.tar.gz KVIrc-1165f3409d4e5badf0c9038c8d84b049ab195741.tar.bz2 KVIrc-1165f3409d4e5badf0c9038c8d84b049ab195741.zip | |
Yet more work on the servers dialog
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4395 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/options')
| -rw-r--r-- | src/modules/options/container.cpp | 26 | ||||
| -rw-r--r-- | src/modules/options/container.h | 3 | ||||
| -rw-r--r-- | src/modules/options/optw_servers.cpp | 127 | ||||
| -rw-r--r-- | src/modules/options/optw_servers.h | 11 |
4 files changed, 126 insertions, 41 deletions
diff --git a/src/modules/options/container.cpp b/src/modules/options/container.cpp index 2cad2fac0..52466acbf 100644 --- a/src/modules/options/container.cpp +++ b/src/modules/options/container.cpp @@ -34,6 +34,7 @@ #include <QPushButton> #include <QDesktopWidget> #include <QEvent> +#include <QGridLayout> #include <QCloseEvent> #include <QIcon> @@ -43,6 +44,8 @@ extern KviOptionsInstanceManager * g_pOptionsInstanceManager; KviOptionsWidgetContainer::KviOptionsWidgetContainer(QWidget * par,bool bModal) : QDialog(par) { + m_pLayout = new QGridLayout(this); + setObjectName("container"); m_pOptionsWidget = 0; setModal(bModal); @@ -53,31 +56,36 @@ KviOptionsWidgetContainer::~KviOptionsWidgetContainer() if(m_pOptionsWidget)delete m_pOptionsWidget; } -void KviOptionsWidgetContainer::setup(KviOptionsWidget * w) +void KviOptionsWidgetContainer::setLeftCornerWidget(QWidget * pWidget) { - QGridLayout * g = new QGridLayout(this); + if(!pWidget) + return; + m_pLayout->addWidget(pWidget,1,0); +} - g->addWidget(w,0,0,1,3); - //g->addMultiCellWidget(w,0,0,0,2); +void KviOptionsWidgetContainer::setup(KviOptionsWidget * w) +{ + m_pLayout->addWidget(w,0,0,1,3); + //g->addMultiCellWidget(w,0,0,0,2); QPushButton * b = new QPushButton(__tr2qs_ctx("&OK","options"),this); KviTalToolTip::add(b,__tr2qs_ctx("Close this dialog, accepting all changes.","options")); //b->setMinimumWidth(m_pCancel->sizeHint().width()); - g->addWidget(b,1,1); + m_pLayout->addWidget(b,1,1); b->setDefault(true); connect(b,SIGNAL(clicked()),this,SLOT(okClicked())); b->setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT))); m_pCancel = new QPushButton(__tr2qs_ctx("Cancel","options"),this); KviTalToolTip::add(m_pCancel,__tr2qs_ctx("Close this dialog, discarding all changes.","options")); - g->addWidget(m_pCancel,1,2); + m_pLayout->addWidget(m_pCancel,1,2); connect(m_pCancel,SIGNAL(clicked()),this,SLOT(cancelClicked())); m_pCancel->setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD))); - g->setRowStretch(0,1); - g->setColumnStretch(0,1); + m_pLayout->setRowStretch(0,1); + m_pLayout->setColumnStretch(0,1); KviOptionsWidgetInstanceEntry * e = g_pOptionsInstanceManager->findInstanceEntry(w->metaObject()->className()); if(e) @@ -85,8 +93,8 @@ void KviOptionsWidgetContainer::setup(KviOptionsWidget * w) setWindowIcon(QIcon(*(g_pIconManager->getSmallIcon(e->iIcon)))); setWindowTitle(e->szName); } - m_pOptionsWidget = w; + m_pOptionsWidget = w; } void KviOptionsWidgetContainer::closeEvent(QCloseEvent *e) diff --git a/src/modules/options/container.h b/src/modules/options/container.h index 555653529..1e647d721 100644 --- a/src/modules/options/container.h +++ b/src/modules/options/container.h @@ -29,6 +29,7 @@ #include <QDialog> class QPushButton; +class QGridLayout; class KviOptionsWidgetContainer : public QDialog { @@ -39,8 +40,10 @@ public: protected: KviOptionsWidget * m_pOptionsWidget; QPushButton * m_pCancel; + QGridLayout * m_pLayout; public: void setup(KviOptionsWidget * w); + void setLeftCornerWidget(QWidget * pWidget); protected: virtual void closeEvent(QCloseEvent *e); virtual void showEvent(QShowEvent *e); diff --git a/src/modules/options/optw_servers.cpp b/src/modules/options/optw_servers.cpp index f9674e39d..bfbfb1f58 100644 --- a/src/modules/options/optw_servers.cpp +++ b/src/modules/options/optw_servers.cpp @@ -26,6 +26,8 @@ #include "optw_proxy.h" #include "optw_nickserv.h" // for the NickServ rule editor +#include "container.h" + #include "kvi_query.h" #include "kvi_channel.h" #include "kvi_locale.h" @@ -1317,22 +1319,6 @@ KviServerOptionsWidget::KviServerOptionsWidget(QWidget * parent) m_pSrvNetEdit = new QLineEdit(gbox); KviTalToolTip::add(m_pSrvNetEdit,__tr2qs_ctx("<center>This is the name of the currently selected server or network</center>","options")); -/* - m_pIPv6Check = new QCheckBox(__tr2qs_ctx("Use IPv6 protocol","options"),gbox); - -#ifndef COMPILE_IPV6_SUPPORT - m_pIPv6Check->setEnabled(false); -#endif - - KviTalToolTip::add(m_pIPv6Check,__tr2qs_ctx("<center>This check identifies IPv6 servers.<br>If enabled, KVIrc will attempt to use the IPv6 protocol " \ - "(thus your OS <b>must</b> have a working IPv6 stack and you <b>must</b> have an IPv6 connection).</center>","options")); - - m_pPortLabel = new QLabel(__tr2qs_ctx("Port:","options"),gbox); - - m_pPortEdit = new QLineEdit(gbox); - KviTalToolTip::add(m_pPortEdit,__tr2qs_ctx("<center>This is the default <b>port</b> that this server will be contacted on.<br>Usually <b>6667</b> is OK.</center>","options")); -*/ - m_pDetailsButton = new QPushButton(__tr2qs_ctx("Advanced...","options"),gbox); connect(m_pDetailsButton,SIGNAL(clicked()),this,SLOT(detailsClicked())); KviTalToolTip::add(m_pDetailsButton,__tr2qs_ctx("<center>Click here to edit advanced options for this entry</center>","options")); @@ -1356,11 +1342,18 @@ KviServerOptionsWidget::KviServerOptionsWidget(QWidget * parent) KviTalToolTip::add(tb,__tr2qs_ctx("<center>This button shows a list of recently used servers. It allows you to quickly find them in the list.</center>","options")); - KviBoolSelector * b = addBoolSelector(0,3,1,3,__tr2qs_ctx("Show this dialog at startup","options"),KviOption_boolShowServersConnectDialogOnStart); - - KviTalToolTip::add(b,__tr2qs_ctx("<center>If this option is enabled, the Servers dialog will appear every time you start KVIrc</center>","options")); + // The "Show this dialog at startup" option is shown only when the server options widget is shown as standalone dialog + if(parent->inherits("KviOptionsWidgetContainer")) + { + KviOptionsWidgetContainer * pContainer = dynamic_cast<KviOptionsWidgetContainer *>(parent); + if(pContainer) + { + KviBoolSelector * b = addBoolSelector(pContainer,__tr2qs_ctx("Show this dialog at startup","options"),KviOption_boolShowServersConnectDialogOnStart); + pContainer->setLeftCornerWidget(b); - // KviBoolSelector * c = addBoolSelector(0,6,2,6,__tr("Close after connection","options"),KviOption_boolCloseServerWidgetAfterConnect); + KviTalToolTip::add(b,__tr2qs_ctx("<center>If this option is enabled, the Servers dialog will appear every time you start KVIrc</center>","options")); + } + } m_pLastEditedItem = 0; @@ -1382,14 +1375,18 @@ KviServerOptionsWidget::~KviServerOptionsWidget() m_pImportFilter = 0; } - if(m_pClipboard)delete m_pClipboard; - if(m_pServerDetailsDialog)delete m_pServerDetailsDialog; - if(m_pNetworkDetailsDialog)delete m_pNetworkDetailsDialog; + if(m_pClipboard) + delete m_pClipboard; + if(m_pServerDetailsDialog) + delete m_pServerDetailsDialog; + if(m_pNetworkDetailsDialog) + delete m_pNetworkDetailsDialog; } void KviServerOptionsWidget::recentServersPopupAboutToShow() { g_pApp->fillRecentServersPopup(m_pRecentPopup); + m_pRecentPopup->insertSeparator(); m_pRecentPopup->insertItem(__tr2qs("Clear Recent Servers List")); } @@ -1397,26 +1394,92 @@ void KviServerOptionsWidget::recentServersPopupAboutToShow() void KviServerOptionsWidget::recentServersPopupClicked(int id) { KviConsole * c = g_pActiveWindow->console(); - if(!c)return; + if(!c) + return; QString szItemText = m_pRecentPopup->text(id); szItemText.remove(QChar('&')); - if(!szItemText.isEmpty()) + if(szItemText.isEmpty()) + return; + if(szItemText == __tr2qs("Clear Recent Servers List")) + { + KviKvsScript::run("option stringlistRecentServers",c); + return; + } + + selectBestServerByUrl(szItemText); +} + +void KviServerOptionsWidget::selectBestServerByUrl(const QString &szUrl) +{ + if(szUrl.isEmpty()) + return; + + KviIrcUrlParts oParts; + + KviIrcUrl::split(szUrl,oParts); + + int uCount = m_pTreeWidget->topLevelItemCount(); + int uIdx = 0; + + KviServerOptionsTreeWidgetItem * pBestCandidate = NULL; + kvi_u32_t uBestCandidateScore = 0; + + while(uIdx < uCount) { - if(szItemText == __tr2qs("Clear Recent Servers List")) + KviServerOptionsTreeWidgetItem * pNet = static_cast<KviServerOptionsTreeWidgetItem *>(m_pTreeWidget->topLevelItem(uIdx)); + + uIdx++; + + if(!pNet) + continue; // huh ? + + int uServerCount = pNet->childCount(); + int uChildIdx = 0; + while(uChildIdx < uServerCount) { - KviKvsScript::run("option stringlistRecentServers",c); - } else { - KviStr szCommand; - QString szText = szItemText; - if(KviIrcUrl::parse(szText.toUtf8().data(),szCommand,KVI_IRCURL_CONTEXT_THIS)) + KviServerOptionsTreeWidgetItem * pServer = static_cast<KviServerOptionsTreeWidgetItem *>(pNet->child(uChildIdx)); + uChildIdx++; + + if(!pServer) + continue; // huh ? + + KviServer * pServerData = pServer->serverData(); + + if(!pServerData) + continue; // umphf... + + kvi_u32_t uScore = 0; + + if(pServerData->hostName().toLower() == oParts.szHost.toLower()) + uScore++; + if(pServerData->port() == oParts.iPort) + uScore++; + if(pServerData->isIPv6() == oParts.bIPv6) + uScore++; + if(pServerData->useSSL() == oParts.bSsl) + uScore++; + + if(uScore > uBestCandidateScore) { - KviKvsScript::run(szCommand.ptr(),c); + uBestCandidateScore = uScore; + pBestCandidate = pServer; + if(uScore >= 4) + { + // exact match + uIdx = uCount; // break the outer loop + break; // break the inner loop + } } } } + + if(pBestCandidate) + m_pTreeWidget->setCurrentItem(pBestCandidate); + } + void KviServerOptionsWidget::connectCurrentClicked() { saveLastItem(); diff --git a/src/modules/options/optw_servers.h b/src/modules/options/optw_servers.h index e3f2e6267..0568bc563 100644 --- a/src/modules/options/optw_servers.h +++ b/src/modules/options/optw_servers.h @@ -60,6 +60,16 @@ public: KviServer * m_pServerData; KviNetwork * m_pNetworkData; public: + KviServer * serverData() const + { + return m_pServerData; + } + + KviNetwork * networkData() const + { + return m_pNetworkData; + } +public: void updateVisibleStrings(); }; @@ -192,6 +202,7 @@ private: void fillServerList(); void saveLastItem(); KviServerOptionsTreeWidgetItem * findNetItem(const QString &netname); + void selectBestServerByUrl(const QString &szUrl); protected slots: void importerDead(); void importServer(const KviServer & s,const QString &network); |
