diff options
| author | 2016-07-31 20:45:22 -0400 | |
|---|---|---|
| committer | 2016-08-03 02:32:22 -0400 | |
| commit | 7d08b0c3d7e1d4450bcb8a96abc7518c5a115917 (patch) | |
| tree | 82c407f0ce531cc4c2fe2a82ed45bb2b171f5251 /src/modules | |
| parent | KviMenubar: ensure Actions entry has an Icon at least. (diff) | |
| download | KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.tar.gz KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.tar.bz2 KVIrc-7d08b0c3d7e1d4450bcb8a96abc7518c5a115917.zip | |
Part 1: Bring KVIrc to the 21st century
Avoid many un-necessary memory allocations as well as start
the migration to unique pointers where appropriate.
Start migrating out of the KVirc standard library into the C++ standard
library.
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/chan/libkvichan.cpp | 68 | ||||
| -rw-r--r-- | src/modules/context/libkvicontext.cpp | 3 | ||||
| -rw-r--r-- | src/modules/filetransferwindow/FileTransferWindow.cpp | 8 | ||||
| -rw-r--r-- | src/modules/trayicon/libkvitrayicon.cpp | 15 | ||||
| -rw-r--r-- | src/modules/url/libkviurl.cpp | 94 | ||||
| -rw-r--r-- | src/modules/url/libkviurl.h | 5 | ||||
| -rw-r--r-- | src/modules/window/UserWindow.cpp | 9 | ||||
| -rw-r--r-- | src/modules/window/libkviwindow.cpp | 64 |
8 files changed, 122 insertions, 144 deletions
diff --git a/src/modules/chan/libkvichan.cpp b/src/modules/chan/libkvichan.cpp index e1c374f6d..bb470b9b7 100644 --- a/src/modules/chan/libkvichan.cpp +++ b/src/modules/chan/libkvichan.cpp @@ -36,6 +36,8 @@ #include "KviIrcConnectionTarget.h" #include "KviIrcConnection.h" +#include <vector> + static KviChannelWindow * chan_kvs_find_channel(KviKvsModuleFunctionCall * c, QString & szChan, bool bNoWarnings = false) { if(szChan.isEmpty()) @@ -1333,13 +1335,12 @@ static bool chan_kvs_fnc_banlist(KviKvsModuleFunctionCall * c) if(!ch) return true; - int idx = 0; - - KviPointerList<KviMaskEntry> * l = ch->modeMasks('b'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('b'); + if(l.empty()) return true; - for(KviMaskEntry * e = l->first(); e; e = l->next()) + int idx = 0; + for(auto e : l) { pArray->set(idx, new KviKvsVariant(e->szMask)); idx++; @@ -1383,13 +1384,12 @@ static bool chan_kvs_fnc_banexceptionlist(KviKvsModuleFunctionCall * c) if(!ch) return true; - int idx = 0; - - KviPointerList<KviMaskEntry> * l = ch->modeMasks('e'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('e'); + if(l.empty()) return true; - for(KviMaskEntry * e = l->first(); e; e = l->next()) + int idx = 0; + for(auto e : l) { pArray->set(idx, new KviKvsVariant(e->szMask)); idx++; @@ -1433,13 +1433,12 @@ static bool chan_kvs_fnc_invitelist(KviKvsModuleFunctionCall * c) if(!ch) return true; - int idx = 0; - - KviPointerList<KviMaskEntry> * l = ch->modeMasks('I'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('I'); + if(l.empty()) return true; - for(KviMaskEntry * e = l->first(); e; e = l->next()) + int idx = 0; + for(auto e : l) { pArray->set(idx, new KviKvsVariant(e->szMask)); idx++; @@ -1486,13 +1485,12 @@ static bool chan_kvs_fnc_masklist(KviKvsModuleFunctionCall * c) if(!ch) return true; - int idx = 0; - - KviPointerList<KviMaskEntry> * l = ch->modeMasks(cMode); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks(cMode); + if(l.empty()) return true; - for(KviMaskEntry * e = l->first(); e; e = l->next()) + int idx = 0; + for(auto e : l) { pArray->set(idx, new KviKvsVariant(e->szMask)); idx++; @@ -1535,14 +1533,14 @@ static bool chan_kvs_fnc_matchban(KviKvsModuleFunctionCall * c) return true; } - KviPointerList<KviMaskEntry> * l = ch->modeMasks('b'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('b'); + if(l.empty()) { c->returnValue()->setNothing(); return true; } - for(KviMaskEntry * e = l->first(); e; e = l->next()) + for(auto e : l) { if(KviQString::matchString(e->szMask, szMask)) { @@ -1589,14 +1587,14 @@ static bool chan_kvs_fnc_matchbanexception(KviKvsModuleFunctionCall * c) return true; } - KviPointerList<KviMaskEntry> * l = ch->modeMasks('e'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('e'); + if(l.empty()) { c->returnValue()->setNothing(); return true; } - for(KviMaskEntry * e = l->first(); e; e = l->next()) + for(auto e : l) { if(KviQString::matchString(e->szMask, szMask)) { @@ -1643,14 +1641,14 @@ static bool chan_kvs_fnc_matchinvite(KviKvsModuleFunctionCall * c) return true; } - KviPointerList<KviMaskEntry> * l = ch->modeMasks('I'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('I'); + if(l.empty()) { c->returnValue()->setNothing(); return true; } - for(KviMaskEntry * e = l->first(); e; e = l->next()) + for(auto e : l) { if(KviQString::matchString(e->szMask, szMask)) { @@ -1704,14 +1702,14 @@ static bool chan_kvs_fnc_matchqban(KviKvsModuleFunctionCall * c) return true; } - KviPointerList<KviMaskEntry> * l = ch->modeMasks('b'); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks('b'); + if(l.empty()) { c->returnValue()->setNothing(); return true; } - for(KviMaskEntry * e = l->first(); e; e = l->next()) + for(auto e : l) { if(KviQString::matchString(e->szMask, szMask)) { @@ -1762,14 +1760,14 @@ static bool chan_kvs_fnc_matchmask(KviKvsModuleFunctionCall * c) return true; } - KviPointerList<KviMaskEntry> * l = ch->modeMasks(cMode); - if(!l) + const std::vector<KviMaskEntry *> & l = ch->modeMasks(cMode); + if(l.empty()) { c->returnValue()->setNothing(); return true; } - for(KviMaskEntry * e = l->first(); e; e = l->next()) + for(auto e : l) { if(KviQString::matchString(e->szMask, szMask)) { diff --git a/src/modules/context/libkvicontext.cpp b/src/modules/context/libkvicontext.cpp index 8fa531894..186fce01c 100644 --- a/src/modules/context/libkvicontext.cpp +++ b/src/modules/context/libkvicontext.cpp @@ -469,9 +469,8 @@ static bool context_kvs_fnc_list(KviKvsModuleFunctionCall * c) { KviKvsArray * pArray = new KviKvsArray(); - KviPointerList<KviWindow> * pWinList = g_pMainWindow->windowList(); int idx = 0; - for(KviWindow * pWnd = pWinList->first(); pWnd; pWnd = pWinList->next()) + for(auto pWnd : g_pMainWindow->windowList()) { if(pWnd->type() == KviWindow::Console) { diff --git a/src/modules/filetransferwindow/FileTransferWindow.cpp b/src/modules/filetransferwindow/FileTransferWindow.cpp index 5a681bb1d..a9c639a49 100644 --- a/src/modules/filetransferwindow/FileTransferWindow.cpp +++ b/src/modules/filetransferwindow/FileTransferWindow.cpp @@ -49,6 +49,7 @@ #include <QKeyEvent> #include <QWidgetAction> #include <QHeaderView> +#include <vector> #ifdef COMPILE_KDE4_SUPPORT #include <kurl.h> @@ -349,11 +350,12 @@ void FileTransferWindow::tipRequest(KviDynamicToolTip * tip, const QPoint & pnt) void FileTransferWindow::fillTransferView() { - KviPointerList<KviFileTransfer> * l = KviFileTransferManager::instance()->transferList(); - if(!l) + std::vector<KviFileTransfer *> l = KviFileTransferManager::instance()->transferList(); + if(l.empty()) return; + FileTransferItem * it; - for(KviFileTransfer * t = l->first(); t; t = l->next()) + for(auto t : l) { it = new FileTransferItem(m_pTableWidget, t); t->setDisplayItem(it); diff --git a/src/modules/trayicon/libkvitrayicon.cpp b/src/modules/trayicon/libkvitrayicon.cpp index 77e4edab4..1516ccabc 100644 --- a/src/modules/trayicon/libkvitrayicon.cpp +++ b/src/modules/trayicon/libkvitrayicon.cpp @@ -52,6 +52,7 @@ #include <stdlib.h> #include <time.h> +#include <map> #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) #define ICON_SIZE 16 @@ -60,7 +61,7 @@ #define ICON_SIZE 48 #endif -extern KVIRC_API KviPointerHashTable<QString, KviWindow> * g_pGlobalWindowDict; +extern KVIRC_API std::map<QString, KviWindow *> g_pGlobalWindowDict; static KviTrayIconWidget * g_pTrayIcon = nullptr; static QPixmap * g_pDock1 = nullptr; @@ -270,10 +271,9 @@ void KviTrayIconWidget::doAway(bool) if(id < 0) { - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - KviConsoleWindow * pConsole = dynamic_cast<KviConsoleWindow *>(wnd); + KviConsoleWindow * pConsole = dynamic_cast<KviConsoleWindow *>(wnd.second); if(pConsole && pConsole->isConnected()) { if(id == -2) @@ -286,7 +286,6 @@ void KviTrayIconWidget::doAway(bool) pConsole->connection()->encodeText(KVI_OPTION_STRING(KviOption_stringAwayMessage)).data()); } } - ++it; } } else @@ -326,13 +325,12 @@ void KviTrayIconWidget::fillContextPopup() QAction * pSeparator = m_pAwayPopup->addSeparator(); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); bool bAllAway = true; bool bAllUnaway = true; int iNetCount = 0; - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - KviConsoleWindow * pConsole = dynamic_cast<KviConsoleWindow *>(wnd); + KviConsoleWindow * pConsole = dynamic_cast<KviConsoleWindow *>(wnd.second); if(pConsole && pConsole->isConnected()) { QAction * id; @@ -351,7 +349,6 @@ void KviTrayIconWidget::fillContextPopup() id->setData(pConsole->context()->id()); iNetCount++; } - ++it; } if(iNetCount == 1) { diff --git a/src/modules/url/libkviurl.cpp b/src/modules/url/libkviurl.cpp index 564c041c5..a22a10451 100644 --- a/src/modules/url/libkviurl.cpp +++ b/src/modules/url/libkviurl.cpp @@ -34,7 +34,6 @@ #include "KviAction.h" #include "KviActionManager.h" #include "KviWindowListBase.h" -#include "KviPointerList.h" #include "KviKvsEventManager.h" #include "KviWindow.h" #include "KviOptions.h" @@ -64,9 +63,9 @@ typedef struct _UrlDlgList const char * g_pUrlListFilename = "/list.kviurl"; const char * g_pBanListFilename = "/list.kviban"; -KviPointerList<KviUrl> * g_pList; -KviPointerList<UrlDlgList> * g_pUrlDlgList; -KviPointerList<QString> * g_pBanList; +std::unordered_set<KviUrl *> g_List; +std::vector<UrlDlgList *> g_UrlDlgList; +std::unordered_set<QString *> g_BanList; ConfigDialog * g_pConfigDialog; QString szConfigPath; @@ -136,7 +135,7 @@ void UrlDialogTreeWidget::paintEvent(QPaintEvent * event) // ---------------------------- CLASS URLDIALOG ------------------------begin // -UrlDialog::UrlDialog(KviPointerList<KviUrl> *) +UrlDialog::UrlDialog(std::unordered_set<KviUrl *>) : KviWindow(KviWindow::Tool, "URL List") { setAutoFillBackground(false); @@ -183,8 +182,8 @@ void UrlDialog::loadList() void UrlDialog::clear() { - g_pList->clear(); - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + g_List.clear(); + for(auto & tmpitem : g_UrlDlgList) { if(tmpitem->dlg) tmpitem->dlg->m_pUrlList->clear(); @@ -204,11 +203,11 @@ void UrlDialog::remove() return; } - for(KviUrl * tmp = g_pList->first(); tmp; tmp = g_pList->next()) + for(auto & tmp : g_List) { if(tmp->url == m_pUrlList->currentItem()->text(0)) { - g_pList->removeRef(tmp); + g_List.erase(tmp); delete m_pUrlList->currentItem(); return; } @@ -237,7 +236,7 @@ void UrlDialog::popup(QTreeWidgetItem * item, const QPoint & point) p.addSeparator(); m_pListPopup = new QMenu("list", nullptr); - for(KviWindow * w = g_pMainWindow->windowList()->first(); w; w = g_pMainWindow->windowList()->next()) + for(auto & w : g_pMainWindow->windowList()) { if((w->type() == KviWindow::Channel) || (w->type() == KviWindow::Query) || (w->type() == KviWindow::DccChat)) { @@ -412,7 +411,7 @@ BanFrame::BanFrame(QWidget * parent, const char * name, bool banEnabled) m_pBanList = new QListWidget(this); m_pBanList->setMinimumHeight(100); loadBanList(); - for(QString * tmp = g_pBanList->first(); tmp; tmp = g_pBanList->next()) + for(auto tmp : g_BanList) { m_pBanList->addItem(*tmp); // load ban list into listbox } @@ -446,7 +445,7 @@ void BanFrame::addBan() QString * pText = new QString(QInputDialog::getText(this, __tr2qs("URL Ban List - KVIrc"), __tr2qs("Enter a URL to ban."), QLineEdit::Normal, QString(), &ok)); if(ok && !pText->isEmpty()) { - g_pBanList->append(pText); + g_BanList.insert(pText); m_pBanList->addItem(*pText); } } @@ -462,11 +461,11 @@ void BanFrame::removeBan() return; } QString item(m_pBanList->currentItem()->text()); - for(QString * tmp = g_pBanList->first(); tmp; tmp = g_pBanList->next()) + for(auto tmp : g_BanList) { if(tmp->compare(item) == 0) { - g_pBanList->removeCurrent(); + g_BanList.erase(tmp); delete m_pBanList->currentItem(); return; } @@ -498,9 +497,9 @@ void saveUrlList() QTextStream stream(&file); - stream << g_pList->count() << endl; + stream << g_List.size() << endl; - for(KviUrl * tmp = g_pList->first(); tmp; tmp = g_pList->next()) + for(auto tmp : g_List) { stream << tmp->url << endl; stream << tmp->window << endl; @@ -523,9 +522,9 @@ void loadUrlList() QTextStream stream(&file); - g_pList->clear(); + g_List.clear(); - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + for(auto tmpitem : g_UrlDlgList) { if(tmpitem->dlg) tmpitem->dlg->m_pUrlList->clear(); @@ -541,9 +540,9 @@ void loadUrlList() tmp->count = stream.readLine().toInt(); tmp->timestamp = stream.readLine(); - g_pList->append(tmp); + g_List.insert(tmp); - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + for(auto tmpitem : g_UrlDlgList) { if(tmpitem->dlg) { @@ -568,8 +567,8 @@ void saveBanList() QTextStream stream(&file); - stream << g_pBanList->count() << endl; - for(QString * tmp = g_pBanList->first(); tmp; tmp = g_pBanList->next()) + stream << g_BanList.size() << endl; + for(auto tmp : g_BanList) { stream << *tmp << endl; } @@ -589,14 +588,14 @@ void loadBanList() QTextStream stream(&file); - g_pBanList->clear(); + g_BanList.clear(); int i = 0; int num = stream.readLine().toInt(); while((!stream.atEnd()) && (i < num)) { QString * tmp = new QString(stream.readLine()); - g_pBanList->append(tmp); + g_BanList.insert(tmp); i++; } file.close(); @@ -618,13 +617,13 @@ void loadBanList() [b]Window[/b]: window where the URL has been shown last[br] [b]Count[/b]: number of URLs shown[br] [b]Timestamp[/b]: date/time when the URL has been shown first[br][br] - + Clicking right on the URL column of the list a menu will popup, through it you can remove the selected item, find the URL in the window it appeared last, and say it to: [i]@Console, Channels, Queries, DCC Chats[/i] and [i]User windows[/i].[br] The list is saved to file when you click on the menu item or when you unload the plugin on condition that you have checked the relative checkbox in configuration dialog.[br][br] - + You can also open the URL in your web browser double clicking on it in the URL list window. */ @@ -634,10 +633,10 @@ static bool url_kvs_cmd_list(KviKvsModuleCommandCall *) if(tmpitem->dlg) return false; - tmpitem->dlg = new UrlDialog(g_pList); + tmpitem->dlg = new UrlDialog(g_List); g_pMainWindow->addWindow(tmpitem->dlg); - for(KviUrl * tmp = g_pList->first(); tmp; tmp = g_pList->next()) + for(auto tmp : g_List) { QString tmpCount; tmpCount.setNum(tmp->count); @@ -648,14 +647,14 @@ static bool url_kvs_cmd_list(KviKvsModuleCommandCall *) UrlDlgList * findFrame() { - UrlDlgList * tmpitem = g_pUrlDlgList->first(); + UrlDlgList * tmpitem = g_UrlDlgList.front(); if(!tmpitem) { UrlDlgList * udl = new UrlDlgList(); udl->dlg = nullptr; udl->menu_id = -1; - g_pUrlDlgList->append(udl); - tmpitem = g_pUrlDlgList->current(); + g_UrlDlgList.push_back(udl); + tmpitem = g_UrlDlgList.back(); } return tmpitem; } @@ -691,7 +690,7 @@ int check_url(KviWindow * w, const QString & szUrl) // return 0 if no occurrence { int tmp = 0; - for(QString * tmpi = g_pBanList->first(); tmpi; tmpi = g_pBanList->next()) + for(auto tmpi : g_BanList) { if(szUrl.indexOf(*tmpi, Qt::CaseInsensitive) != -1) tmp++; @@ -699,7 +698,7 @@ int check_url(KviWindow * w, const QString & szUrl) // return 0 if no occurrence if(tmp > 0) return tmp; - for(KviUrl * u = g_pList->first(); u; u = g_pList->next()) + for(auto u : g_List) { if(u->url == szUrl) { @@ -709,7 +708,7 @@ int check_url(KviWindow * w, const QString & szUrl) // return 0 if no occurrence } } - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + for(auto tmpitem : g_UrlDlgList) { if(tmpitem->dlg) { @@ -754,8 +753,8 @@ bool urllist_module_event_onUrl(KviKvsModuleEventCall * c) tmp->count = 1; tmp->timestamp = tmpTimestamp; - g_pList->append(tmp); - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + g_List.insert(tmp); + for(auto tmpitem : g_UrlDlgList) { if(tmpitem->dlg) { @@ -784,15 +783,6 @@ bool urllist_module_event_onUrl(KviKvsModuleEventCall * c) static bool url_module_init(KviModule * m) { - g_pList = new KviPointerList<KviUrl>; - g_pList->setAutoDelete(true); - - g_pUrlDlgList = new KviPointerList<UrlDlgList>; - g_pUrlDlgList->setAutoDelete(true); - - g_pBanList = new KviPointerList<QString>; - g_pBanList->setAutoDelete(true); - KVSM_REGISTER_SIMPLE_COMMAND(m, "list", url_kvs_cmd_list); KVSM_REGISTER_SIMPLE_COMMAND(m, "config", url_kvs_cmd_config); @@ -805,7 +795,7 @@ static bool url_module_init(KviModule * m) UrlDlgList * udl = new UrlDlgList(); udl->dlg = nullptr; - g_pUrlDlgList->append(udl); + g_UrlDlgList.push_back(udl); return true; } @@ -816,19 +806,15 @@ static bool url_module_cleanup(KviModule *) cfg.setGroup("ConfigDialog"); if(cfg.readBoolEntry("SaveUrlListOnUnload", false) == true) saveUrlList(); - for(UrlDlgList * tmpitem = g_pUrlDlgList->first(); tmpitem; tmpitem = g_pUrlDlgList->next()) + for(auto tmpitem : g_UrlDlgList) { if(tmpitem->dlg) tmpitem->dlg->close(); } - delete g_pList; - g_pList = nullptr; - delete g_pBanList; - g_pBanList = nullptr; - - delete g_pUrlDlgList; - g_pUrlDlgList = nullptr; + g_List.clear(); + g_BanList.clear(); + g_UrlDlgList.clear(); return true; } diff --git a/src/modules/url/libkviurl.h b/src/modules/url/libkviurl.h index 56203de3c..623d11b5a 100644 --- a/src/modules/url/libkviurl.h +++ b/src/modules/url/libkviurl.h @@ -45,6 +45,9 @@ #include <QCheckBox> #include <QListWidget> +#include <unordered_set> +#include <vector> + typedef struct _KviUrl { QString url; @@ -72,7 +75,7 @@ class UrlDialog : public KviWindow { Q_OBJECT public: - UrlDialog(KviPointerList<KviUrl> * g_pList); + UrlDialog(std::unordered_set<KviUrl *> g_List); ~UrlDialog(); private: diff --git a/src/modules/window/UserWindow.cpp b/src/modules/window/UserWindow.cpp index 48d34c734..e1d7500ab 100644 --- a/src/modules/window/UserWindow.cpp +++ b/src/modules/window/UserWindow.cpp @@ -28,12 +28,15 @@ #include "KviMainWindow.h" #include "KviConsoleWindow.h" -extern KviPointerList<UserWindow> * g_pUserWindowList; +#include <algorithm> +#include <map> + +extern std::vector<UserWindow *> g_pUserWindowList; UserWindow::UserWindow(const char * pcName, QString & szIcon, KviConsoleWindow * pConsole, int iCreationFlags) : KviWindow(KviWindow::UserWindow, pcName, pConsole) { - g_pUserWindowList->append(this); + g_pUserWindowList.push_back(this); m_szIcon = szIcon; @@ -55,7 +58,7 @@ UserWindow::~UserWindow() { if(context()) context()->unregisterContextWindow(this); - g_pUserWindowList->removeRef(this); + g_pUserWindowList.erase(std::remove(g_pUserWindowList.begin(), g_pUserWindowList.end(), this), g_pUserWindowList.end()); } QPixmap * UserWindow::myIconPtr() diff --git a/src/modules/window/libkviwindow.cpp b/src/modules/window/libkviwindow.cpp index ea690f02a..cb7e4be88 100644 --- a/src/modules/window/libkviwindow.cpp +++ b/src/modules/window/libkviwindow.cpp @@ -38,9 +38,10 @@ #include "KviModuleManager.h" #include "KviMemory.h" #include "KviChannelWindow.h" -#include "KviPointerHashTable.h" #include <QTimer> +#include <map> +#include <vector> #ifdef COMPILE_CRYPT_SUPPORT #include "KviCryptEngine.h" @@ -50,8 +51,8 @@ extern KVIRC_API KviCryptEngineManager * g_pCryptEngineManager; #endif // KviApplication.cpp -extern KVIRC_API KviPointerHashTable<QString, KviWindow> * g_pGlobalWindowDict; -KviPointerList<UserWindow> * g_pUserWindowList = nullptr; +extern KVIRC_API std::map<QString, KviWindow *> g_pGlobalWindowDict; +std::vector<UserWindow *> g_pUserWindowList; // $window.caption $window.x $window.y $window.width $window.height $window.isActive $window.type // $window.input.text $window.input.cursorpos $window.input.textlen @@ -841,78 +842,72 @@ static bool window_kvs_fnc_list(KviKvsModuleFunctionCall * c) { // all contexts but no "no_context" windows bool bAllWindows = KviQString::equalCI(szType, "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(wnd->context()) + if(wnd.second->context()) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } - ++it; } } else if(KviQString::equalCI(szContext, "any")) { // all contexts and also "no_context" windows bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } - ++it; } } else if(KviQString::equalCI(szContext, "none")) { // only "no_context" windows bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(!wnd->context()) + if(!wnd.second->context()) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } - ++it; } } else @@ -942,30 +937,28 @@ static bool window_kvs_fnc_list(KviKvsModuleFunctionCall * c) } bool bAllWindows = KviQString::equalCI(szType.toLower(), "all"); - KviPointerHashTableIterator<QString, KviWindow> it(*g_pGlobalWindowDict); - while(KviWindow * wnd = it.current()) + for(auto & wnd : g_pGlobalWindowDict) { - if(wnd->context()) + if(wnd.second->context()) { - if(wnd->context()->id() == uId) + if(wnd.second->context()->id() == uId) { if(bAllWindows) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } else { - if(szType.toLower() == wnd->typeString()) + if(szType.toLower() == wnd.second->typeString()) { - pArray->set(id, new KviKvsVariant(QString(wnd->id()))); + pArray->set(id, new KviKvsVariant(QString(wnd.second->id()))); id++; } } } } - ++it; } } return true; @@ -1505,9 +1498,6 @@ static bool window_kvs_cmd_fake(KviKvsModuleCommandCall * c) static bool window_module_init(KviModule * m) { - g_pUserWindowList = new KviPointerList<UserWindow>(); - g_pUserWindowList->setAutoDelete(false); - KVSM_REGISTER_FUNCTION(m, "activityTemperature", window_kvs_fnc_activityTemperature); KVSM_REGISTER_FUNCTION(m, "activityLevel", window_kvs_fnc_activityLevel); KVSM_REGISTER_FUNCTION(m, "highlightLevel", window_kvs_fnc_highlightLevel); @@ -1550,15 +1540,15 @@ static bool window_module_init(KviModule * m) static bool window_module_cleanup(KviModule *) { - while(UserWindow * w = g_pUserWindowList->first()) + for(auto & w : g_pUserWindowList) w->close(); - delete g_pUserWindowList; + g_pUserWindowList.clear(); return true; } static bool window_module_can_unload(KviModule *) { - return g_pUserWindowList->isEmpty(); + return g_pUserWindowList.empty(); } KVIRC_MODULE( |
