diff --git a/.gitignore b/.gitignore index ec8673a..6e86115 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +# Releases +release/ +macos/package/ +macos/release/ +macos/grumpy.icns +macos/grumpy_logo.png + # C++ objects and libs *.slo *.lo diff --git a/src/GrumpyIRC/lib/favoriteswin.cpp b/src/GrumpyIRC/lib/favoriteswin.cpp index 1e80794..1c4c1bc 100644 --- a/src/GrumpyIRC/lib/favoriteswin.cpp +++ b/src/GrumpyIRC/lib/favoriteswin.cpp @@ -8,18 +8,54 @@ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Lesser General Public License for more details. -// Copyright (c) Petr Bena 2015 - 2018 +// Copyright (c) Petr Bena 2015 - 2021 #include "favoriteswin.h" +#include "grumpyconf.h" #include "ui_favoriteswin.h" +#include "networkwin.h" +#include "identityeditorwin.h" +#include "mainwindow.h" +#include +#include +#include +#include using namespace GrumpyIRC; +void FavoritesWin::Load() +{ + FavoritesWin::loadIdentities(); + FavoritesWin::loadNetworks(); +} + +void FavoritesWin::Save() +{ + FavoritesWin::saveIdentities(); + FavoritesWin::saveNetworks(); +} + FavoritesWin::FavoritesWin(QWidget *parent) : QDialog(parent), ui(new Ui::FavoritesWin) { this->ui->setupUi(this); - this->ui->comboBox->addItem("Local"); - this->ui->comboBox->setCurrentIndex(0); + + QStringList heading_1; + heading_1 << "ID" << "Network name" << "Hostname"; + this->ui->tv_NetworkList->verticalHeader()->setVisible(false); + this->ui->tv_NetworkList->setColumnCount(heading_1.size()); + this->ui->tv_NetworkList->setShowGrid(false); + this->ui->tv_NetworkList->setHorizontalHeaderLabels(heading_1); + + this->RefreshNetworks(); + + QStringList heading_2; + heading_2 << "ID" << "Nick" << "Ident" << "Real Name" << "Auto connect"; + this->ui->tv_IdentityList->verticalHeader()->setVisible(false); + this->ui->tv_IdentityList->setColumnCount(heading_2.size()); + this->ui->tv_IdentityList->setShowGrid(false); + this->ui->tv_IdentityList->setHorizontalHeaderLabels(heading_2); + + this->RefreshIdentities(); } FavoritesWin::~FavoritesWin() @@ -27,7 +63,229 @@ FavoritesWin::~FavoritesWin() delete this->ui; } -void GrumpyIRC::FavoritesWin::on_tableWidget_customContextMenuRequested(const QPoint &pos) +void FavoritesWin::RefreshNetworks() +{ + while (this->ui->tv_NetworkList->rowCount()) + this->ui->tv_NetworkList->removeRow(0); + + int row = 0; + QList network_list = NetworkInfo::NetworksInfo.keys(); + qSort(network_list); + + foreach (int id, network_list) + { + NetworkInfo *network = NetworkInfo::NetworksInfo[id]; + this->ui->tv_NetworkList->insertRow(row); + this->ui->tv_NetworkList->setItem(row, 0, new QTableWidgetItem(QString::number(network->ID))); + this->ui->tv_NetworkList->setItem(row, 1, new QTableWidgetItem(network->NetworkName)); + this->ui->tv_NetworkList->setItem(row, 2, new QTableWidgetItem(network->Hostname)); + this->ui->tv_NetworkList->setItem(row, 3, new QTableWidgetItem(Generic::Bool2String(network->AutoReconnect))); + row++; + } +} + +void FavoritesWin::RefreshIdentities() +{ + while(this->ui->tv_IdentityList->rowCount()) + this->ui->tv_IdentityList->removeRow(0); + + int row = 0; + QList identity_list = Identity::Identities.keys(); + qSort(identity_list); + + foreach (int id, identity_list) + { + Identity *identity = Identity::Identities[id]; + this->ui->tv_IdentityList->insertRow(row); + this->ui->tv_IdentityList->setItem(row, 0, new QTableWidgetItem(QString::number(identity->ID))); + this->ui->tv_IdentityList->setItem(row, 1, new QTableWidgetItem(identity->Nick)); + this->ui->tv_IdentityList->setItem(row, 2, new QTableWidgetItem(identity->Ident)); + this->ui->tv_IdentityList->setItem(row, 3, new QTableWidgetItem(identity->RealName)); + row++; + } +} + +void GrumpyIRC::FavoritesWin::on_tv_IdentityList_customContextMenuRequested(const QPoint &pos) +{ + QPoint globalPos = this->ui->tv_IdentityList->viewport()->mapToGlobal(pos); + QMenu Menu; + // Items + QAction *menuInsert = new QAction("Insert", &Menu); + Menu.addAction(menuInsert); + QAction *menuEdit = new QAction("Edit", &Menu); + Menu.addAction(menuEdit); + QAction *menuRemove = new QAction("Remove", &Menu); + Menu.addAction(menuRemove); + + QList selected = this->selectedIdents(); + if (selected.count() != 1) + { + menuEdit->setEnabled(false); + } + + + QAction* selectedItem = Menu.exec(globalPos); + if (!selectedItem) + return; + if (selectedItem == menuInsert) + { + IdentityEditorWin iw; + iw.exec(); + this->RefreshIdentities(); + } else if (selectedItem == menuRemove) + { + foreach (int id, selected) + { + if (Identity::Identities.contains(id)) + { + // Remove reference to this identity from all networks + foreach (int network_id, NetworkInfo::NetworksInfo.keys()) + { + if (NetworkInfo::NetworksInfo[network_id]->PreferredIdentity == id) + NetworkInfo::NetworksInfo[network_id]->PreferredIdentity = -1; + } + + delete Identity::Identities[id]; + Identity::Identities.remove(id); + } + } + this->RefreshIdentities(); + } else if (selectedItem == menuEdit) + { + IdentityEditorWin iw; + iw.Load(selected[0]); + iw.exec(); + } +} + +void GrumpyIRC::FavoritesWin::on_tv_NetworkList_customContextMenuRequested(const QPoint &pos) +{ + QPoint globalPos = this->ui->tv_NetworkList->viewport()->mapToGlobal(pos); + QMenu Menu; + // Items + QAction *menuConnect = new QAction("Connect", &Menu); + Menu.addAction(menuConnect); + Menu.addSeparator(); + QAction *menuInsert = new QAction("Insert", &Menu); + Menu.addAction(menuInsert); + QAction *menuEdit = new QAction("Edit", &Menu); + Menu.addAction(menuEdit); + QAction *menuRemove = new QAction("Remove", &Menu); + Menu.addAction(menuRemove); + + QList selected = this->selectedNetworks(); + + if (selected.count() != 1) + { + menuConnect->setEnabled(false); + menuEdit->setEnabled(false); + } + + QAction* selectedItem = Menu.exec(globalPos); + if (!selectedItem) + return; + if (selectedItem == menuInsert) + { + NetworkWin nx; + nx.exec(); + this->RefreshNetworks(); + } else if (selectedItem == menuRemove) + { + foreach (int id, selected) + { + if (NetworkInfo::NetworksInfo.contains(id)) + { + delete NetworkInfo::NetworksInfo[id]; + NetworkInfo::NetworksInfo.remove(id); + } + } + this->RefreshNetworks(); + } else if (selectedItem == menuEdit) + { + NetworkWin nx; + nx.Load(selected[0]); + nx.exec(); + this->RefreshNetworks(); + } else if (selectedItem == menuConnect) + { + NetworkInfo *network = NetworkInfo::NetworksInfo[selected[0]]; + MainWindow::Main->OpenServer(network->ToServerAddress()); + this->close(); + } +} + +void FavoritesWin::saveNetworks() +{ + QList networks = NetworkInfo::NetworksInfo.keys(); + QHash list; + foreach (int id, networks) + { + list.insert(QString::number(id), QVariant(NetworkInfo::NetworksInfo[id]->ToHash())); + } + CONF->SetNetworks(list); +} + +void FavoritesWin::loadNetworks() +{ + QHash nl = CONF->GetNetworks(); + foreach (QString key, nl.keys()) + { + QHash network_data = nl[key].toHash(); + NetworkInfo *network_info = new NetworkInfo(network_data); + NetworkInfo::NetworksInfo.insert(network_info->ID, network_info); + } +} + +void FavoritesWin::saveIdentities() +{ + QList identities = Identity::Identities.keys(); + QHash list; + foreach (int id, identities) + { + list.insert(QString::number(id), QVariant(Identity::Identities[id]->ToHash())); + } + CONF->SetIdentities(list); +} + +void FavoritesWin::loadIdentities() +{ + QHash nl = CONF->GetIdentities(); + foreach (QString key, nl.keys()) + { + QHash identity_hash = nl[key].toHash(); + Identity *identity = new Identity(identity_hash); + Identity::Identities.insert(identity->ID, identity); + } +} + +QList FavoritesWin::selectedNetworks() +{ + QList results; + QList items = this->ui->tv_NetworkList->selectedItems(); + foreach (QTableWidgetItem *xx, items) + { + if (xx->column() > 0) + continue; + int id = xx->text().toInt(); + if (!results.contains(id)) + results.append(id); + } + + return results; +} + +QList FavoritesWin::selectedIdents() { + QList results; + QList items = this->ui->tv_IdentityList->selectedItems(); + foreach (QTableWidgetItem *xx, items) + { + if (xx->column() > 0) + continue; + int id = xx->text().toInt(); + if (!results.contains(id)) + results.append(id); + } + return results; } diff --git a/src/GrumpyIRC/lib/favoriteswin.h b/src/GrumpyIRC/lib/favoriteswin.h index ceb3e01..9ee606b 100644 --- a/src/GrumpyIRC/lib/favoriteswin.h +++ b/src/GrumpyIRC/lib/favoriteswin.h @@ -8,7 +8,7 @@ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Lesser General Public License for more details. -// Copyright (c) Petr Bena 2015 - 2018 +// Copyright (c) Petr Bena 2015 - 2021 #ifndef FAVORITESWIN_H #define FAVORITESWIN_H @@ -28,13 +28,26 @@ namespace GrumpyIRC Q_OBJECT public: + static void Load(); + static void Save(); + explicit FavoritesWin(QWidget *parent = 0); ~FavoritesWin(); + void RefreshNetworks(); + void RefreshIdentities(); private slots: - void on_tableWidget_customContextMenuRequested(const QPoint &pos); + void on_tv_IdentityList_customContextMenuRequested(const QPoint &pos); + void on_tv_NetworkList_customContextMenuRequested(const QPoint &pos); private: + static void saveNetworks(); + static void loadNetworks(); + static void saveIdentities(); + static void loadIdentities(); + + QList selectedNetworks(); + QList selectedIdents(); Ui::FavoritesWin *ui; }; } diff --git a/src/GrumpyIRC/lib/favoriteswin.ui b/src/GrumpyIRC/lib/favoriteswin.ui index b73b6c6..4d9b993 100644 --- a/src/GrumpyIRC/lib/favoriteswin.ui +++ b/src/GrumpyIRC/lib/favoriteswin.ui @@ -18,11 +18,100 @@ :/icons/img/grumpy_logo.png:/icons/img/grumpy_logo.png + + 0 + + + 0 + + + 0 + + + 0 + - - - - + + + 0 + + + + Networks + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + QAbstractItemView::MultiSelection + + + QAbstractItemView::SelectRows + + + + + + + + Identities + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::MultiSelection + + + QAbstractItemView::SelectRows + + + + + + diff --git a/src/GrumpyIRC/lib/grumpyconf.cpp b/src/GrumpyIRC/lib/grumpyconf.cpp index 70a9561..86ca405 100644 --- a/src/GrumpyIRC/lib/grumpyconf.cpp +++ b/src/GrumpyIRC/lib/grumpyconf.cpp @@ -416,6 +416,26 @@ void GrumpyConf::SetContinuousLoggingPath(QString path) GCFG->SetValue("continuous_logging_path", path); } +QHash GrumpyConf::GetIdentities() +{ + return GCFG->GetValueAsHash("identities"); +} + +QHash GrumpyConf::GetNetworks() +{ + return GCFG->GetValueAsHash("networks"); +} + +void GrumpyConf::SetIdentities(const QHash &list) +{ + GCFG->SetValue("identities", list); +} + +void GrumpyConf::SetNetworks(const QHash &hash) +{ + GCFG->SetValue("networks", hash); +} + void GrumpyConf::SetProxy(int proxy) { GCFG->SetValue("proxy", proxy); diff --git a/src/GrumpyIRC/lib/grumpyconf.h b/src/GrumpyIRC/lib/grumpyconf.h index 162f335..bb7cdaa 100644 --- a/src/GrumpyIRC/lib/grumpyconf.h +++ b/src/GrumpyIRC/lib/grumpyconf.h @@ -112,6 +112,10 @@ namespace GrumpyIRC void SetContinuousLoggingEnabled(bool enabled); QString GetContinuousLoggingPath(); void SetContinuousLoggingPath(QString path); + QHash GetIdentities(); + QHash GetNetworks(); + void SetIdentities(const QHash &list); + void SetNetworks(const QHash &hash); ///////////////////////////////////////////////////////////////////////// // Proxy diff --git a/src/GrumpyIRC/lib/identityeditorwin.cpp b/src/GrumpyIRC/lib/identityeditorwin.cpp new file mode 100644 index 0000000..705ad13 --- /dev/null +++ b/src/GrumpyIRC/lib/identityeditorwin.cpp @@ -0,0 +1,62 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#include "identityeditorwin.h" +#include "ui_identityeditorwin.h" +#include "../../libcore/identity.h" + +using namespace GrumpyIRC; + +IdentityEditorWin::IdentityEditorWin(QWidget *parent) : QDialog(parent), ui(new Ui::IdentityEditorWin) +{ + this->ui->setupUi(this); +} + +IdentityEditorWin::~IdentityEditorWin() +{ + delete this->ui; +} + +void IdentityEditorWin::Load(int id) +{ + if (!Identity::Identities.contains(id)) + return; + + Identity *x = Identity::Identities[id]; + this->identID = id; + this->ui->le_RealName->setText(x->RealName); + this->ui->le_Nick->setText(x->Nick); + this->ui->le_Ident->setText(x->Ident); + this->ui->le_AwayMsg->setText(x->AwayMessage); +} + +void GrumpyIRC::IdentityEditorWin::on_pbSave_clicked() +{ + if (this->identID < 0) + { + Identity *i = new Identity(this->ui->le_Nick->text(), this->ui->le_Ident->text(), this->ui->le_RealName->text(), this->ui->le_AwayMsg->text()); + Identity::Identities.insert(i->ID, i); + this->close(); + return; + } + Identity *x = Identity::Identities[this->identID]; + x->Nick = this->ui->le_Nick->text(); + x->Ident = this->ui->le_Ident->text(); + x->RealName = this->ui->le_RealName->text(); + x->AwayMessage = this->ui->le_AwayMsg->text(); + this->close(); +} + +void GrumpyIRC::IdentityEditorWin::on_pbCancel_clicked() +{ + this->close(); +} diff --git a/src/GrumpyIRC/lib/identityeditorwin.h b/src/GrumpyIRC/lib/identityeditorwin.h new file mode 100644 index 0000000..16fa94e --- /dev/null +++ b/src/GrumpyIRC/lib/identityeditorwin.h @@ -0,0 +1,44 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#ifndef IDENTITYEDITORWIN_H +#define IDENTITYEDITORWIN_H + +#include + +namespace Ui +{ + class IdentityEditorWin; +} + +namespace GrumpyIRC +{ + class IdentityEditorWin : public QDialog + { + Q_OBJECT + public: + explicit IdentityEditorWin(QWidget *parent = nullptr); + ~IdentityEditorWin(); + void Load(int id); + + private slots: + void on_pbSave_clicked(); + + void on_pbCancel_clicked(); + + private: + int identID = -1; + Ui::IdentityEditorWin *ui; + }; +} + +#endif // IDENTITYEDITORWIN_H diff --git a/src/GrumpyIRC/lib/identityeditorwin.ui b/src/GrumpyIRC/lib/identityeditorwin.ui new file mode 100644 index 0000000..c4938a8 --- /dev/null +++ b/src/GrumpyIRC/lib/identityeditorwin.ui @@ -0,0 +1,111 @@ + + + IdentityEditorWin + + + + 0 + 0 + 373 + 252 + + + + Identity editor + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Nick + + + + + + + Ident + + + + + + + Real name + + + + + + + Away message + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 81 + + + + + + + + + + Save + + + true + + + + + + + Cancel + + + + + + + + + + diff --git a/src/GrumpyIRC/lib/mainwindow.cpp b/src/GrumpyIRC/lib/mainwindow.cpp index 4cdfb9c..32bf2f8 100644 --- a/src/GrumpyIRC/lib/mainwindow.cpp +++ b/src/GrumpyIRC/lib/mainwindow.cpp @@ -8,7 +8,7 @@ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Lesser General Public License for more details. -// Copyright (c) Petr Bena 2015 - 2020 +// Copyright (c) Petr Bena 2015 - 2021 #include "aboutwin.h" #include "corewrapper.h" @@ -157,6 +157,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi Proxy::Init(); this->SetupAutoAway(); + // Load identities and favorite networks + FavoritesWin::Load(); + if (!CONF->SafeMode) this->Execute(CONF->GetAutorun()); @@ -180,7 +183,6 @@ MainWindow::MainWindow(bool fork, MainWindow *parent) // Try to restore geometry this->restoreGeometry(GCFG->GetValue("mainwindow_geometry").toByteArray()); this->restoreState(GCFG->GetValue("mainwindow_state").toByteArray()); - this->ui->actionFavorites->setVisible(false); } MainWindow::~MainWindow() @@ -479,6 +481,7 @@ void MainWindow::on_actionExit_triggered() void MainWindow::closeEvent(QCloseEvent *event) { + (void) event; Exit(); } @@ -513,9 +516,10 @@ void MainWindow::on_actionOpen_window_triggered() void MainWindow::on_actionFavorites_triggered() { - FavoritesWin *favorites = new FavoritesWin(this); - favorites->setAttribute(Qt::WA_DeleteOnClose); - favorites->show(); + FavoritesWin favorites(this); + favorites.exec(); + FavoritesWin::Save(); + CONF->Save(); } void MainWindow::on_actionToggle_secret_triggered() @@ -525,13 +529,13 @@ void MainWindow::on_actionToggle_secret_triggered() void MainWindow::on_actionProxy_triggered() { - Proxy p; + Proxy p(this); p.exec(); } void MainWindow::on_actionEnable_proxy_toggled(bool arg1) { - Proxy p; + Proxy p(this); p.Enable(arg1); } diff --git a/src/GrumpyIRC/lib/mainwindow.ui b/src/GrumpyIRC/lib/mainwindow.ui index 2c39a6f..cbc186f 100644 --- a/src/GrumpyIRC/lib/mainwindow.ui +++ b/src/GrumpyIRC/lib/mainwindow.ui @@ -35,9 +35,9 @@ + - @@ -134,7 +134,7 @@ &Favorites - false + true diff --git a/src/GrumpyIRC/lib/networkwin.cpp b/src/GrumpyIRC/lib/networkwin.cpp new file mode 100644 index 0000000..8e188d5 --- /dev/null +++ b/src/GrumpyIRC/lib/networkwin.cpp @@ -0,0 +1,91 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#include "networkwin.h" +#include +#include +#include "ui_networkwin.h" + +using namespace GrumpyIRC; + +NetworkWin::NetworkWin(QWidget *parent) : QDialog(parent), ui(new Ui::NetworkWin) +{ + this->ui->setupUi(this); + QList identities = Identity::Identities.keys(); + int i = 1; + this->ui->cb_IdentityNumber->addItem("Default"); + this->identityMap.insert(0, -1); + foreach (int identity, identities) + { + this->identityMap.insert(i, identity); + this->ui->cb_IdentityNumber->addItem(Identity::Identities[identity]->ToString()); + i++; + } +} + +NetworkWin::~NetworkWin() +{ + delete this->ui; +} + +void NetworkWin::Load(int network_id) +{ + NetworkInfo *x = NetworkInfo::NetworksInfo[network_id]; + this->networkID = network_id; + this->ui->le_Port->setText(QString::number(x->Port)); + this->ui->checkBox_SSL->setChecked(x->SSL); + this->ui->le_HostName->setText(x->Hostname); + this->ui->le_Name->setText(x->NetworkName); + // find identity ID + if (x->PreferredIdentity > -1) + { + int identity = -1; + foreach (int id, this->identityMap.keys()) + { + if (this->identityMap[id] == x->PreferredIdentity) + { + identity = id; + break; + } + } + if (identity > -1) + this->ui->cb_IdentityNumber->setCurrentIndex(identity); + } +} + +void GrumpyIRC::NetworkWin::on_pushSave_clicked() +{ + if (this->networkID < 0) + { + NetworkInfo *network = new NetworkInfo(this->ui->le_Name->text(), + this->ui->le_HostName->text(), + this->ui->le_Port->text().toInt(), + this->ui->checkBox_SSL->isChecked(), + this->identityMap[this->ui->cb_IdentityNumber->currentIndex()]); + NetworkInfo::NetworksInfo.insert(network->ID, network); + this->close(); + return; + } + NetworkInfo *x = NetworkInfo::NetworksInfo[this->networkID]; + x->NetworkName = this->ui->le_Name->text(); + x->Hostname = this->ui->le_HostName->text(); + x->Port = this->ui->le_Port->text().toInt(); + x->SSL = this->ui->checkBox_SSL->isChecked(); + x->PreferredIdentity = this->identityMap[this->ui->cb_IdentityNumber->currentIndex()]; + + this->close(); +} + +void GrumpyIRC::NetworkWin::on_pushExit_clicked() +{ + this->close(); +} diff --git a/src/libcore/favorite.h b/src/GrumpyIRC/lib/networkwin.h similarity index 51% rename from src/libcore/favorite.h rename to src/GrumpyIRC/lib/networkwin.h index b1ce559..f28c870 100644 --- a/src/libcore/favorite.h +++ b/src/GrumpyIRC/lib/networkwin.h @@ -8,34 +8,37 @@ //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Lesser General Public License for more details. -// Copyright (c) Petr Bena 2015 +// Copyright (c) Petr Bena 2021 -#ifndef FAVORITE_H -#define FAVORITE_H +#ifndef NETWORKWIN_H +#define NETWORKWIN_H -#include "definitions.h" -#include "../libirc/libirc/serializableitem.h" -#include "libcore_global.h" +#include -#include -#include +namespace Ui { + class NetworkWin; +} namespace GrumpyIRC { - class LIBCORESHARED_EXPORT Favorite : public libirc::SerializableItem + class NetworkWin : public QDialog { + Q_OBJECT + public: - Favorite(); + explicit NetworkWin(QWidget *parent = nullptr); + ~NetworkWin(); + void Load(int network_id); + private slots: + void on_pushSave_clicked(); + void on_pushExit_clicked(); private: - QString name; - QString host; - QString nick; - QString username; - QString password; - + QHash identityMap; + Ui::NetworkWin *ui; + int networkID = -1; }; } -#endif // FAVORITE_H +#endif // NETWORKWIN_H diff --git a/src/GrumpyIRC/lib/networkwin.ui b/src/GrumpyIRC/lib/networkwin.ui new file mode 100644 index 0000000..773c06d --- /dev/null +++ b/src/GrumpyIRC/lib/networkwin.ui @@ -0,0 +1,110 @@ + + + NetworkWin + + + + 0 + 0 + 470 + 220 + + + + Network + + + + + + + + Name + + + + + + + + + + Hostname + + + + + + + Port + + + + + + + Identity + + + + + + + + + + 6667 + + + + + + + + + + + + SSL + + + + + + + + + Save + + + true + + + + + + + Cancel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/GrumpyIRC/lib/scrollbackframe.cpp b/src/GrumpyIRC/lib/scrollbackframe.cpp index f56038b..e47e76c 100644 --- a/src/GrumpyIRC/lib/scrollbackframe.cpp +++ b/src/GrumpyIRC/lib/scrollbackframe.cpp @@ -276,7 +276,6 @@ static QString ItemToTXTString(const ScrollbackItem &item) QString format_string = CONF->GetLineFormat(); QString text = item.GetText(); QString user = item.GetUser().GetNick(); - bool system = false; switch (item.GetType()) { case ScrollbackItemType_Act: @@ -284,14 +283,12 @@ static QString ItemToTXTString(const ScrollbackItem &item) format_string.replace("$string", CONF->GetActionFormat()); break; case ScrollbackItemType_Join: - system = true; format_string.replace("$string", CONF->GetActionFormat()); user = item.GetUser().ToString(); text = "joined channel"; //result = FormatAction(item.GetUser(), "joined channel", true); break; case ScrollbackItemType_Part: - system = true; format_string.replace("$string", CONF->GetActionFormat()); user = item.GetUser().ToString(); if (item.GetText().isEmpty()) @@ -300,22 +297,18 @@ static QString ItemToTXTString(const ScrollbackItem &item) text = "left channel (" + item.GetText() + ")"; break; case ScrollbackItemType_Quit: - system = true; format_string.replace("$string", CONF->GetActionFormat()); user = item.GetUser().ToString(); text = "quit (" + item.GetText() + ")"; break; case ScrollbackItemType_Kick: - system = true; format_string.replace("$string", CONF->GetActionFormat()); break; case ScrollbackItemType_Mode: - system = true; format_string.replace("$string", CONF->GetActionFormat()); text = "set mode " + item.GetText(); break; case ScrollbackItemType_Nick: - system = true; format_string.replace("$string", CONF->GetActionFormat()); text = "changed nick to " + item.GetText(); break; @@ -334,7 +327,6 @@ static QString ItemToTXTString(const ScrollbackItem &item) case ScrollbackItemType_SystemWarning: break; case ScrollbackItemType_Topic: - system = true; format_string.replace("$string", CONF->GetActionFormat()); text = "changed topic to: " + item.GetText(); break; diff --git a/src/libcore/configuration.cpp b/src/libcore/configuration.cpp index 614e098..f32621d 100644 --- a/src/libcore/configuration.cpp +++ b/src/libcore/configuration.cpp @@ -80,6 +80,14 @@ QString Configuration::GetValueAsString(const QString &key, const QString &defau return this->Options[key].toString(); } +QHash Configuration::GetValueAsHash(const QString &key, const QHash &default_value) +{ + if (!this->Options.contains(key)) + return default_value; + + return this->Options[key].toHash(); +} + int Configuration::GetValueAsInt(const QString &key, int none) { if (!this->Options.contains(key)) diff --git a/src/libcore/configuration.h b/src/libcore/configuration.h index c494ac1..bf07931 100644 --- a/src/libcore/configuration.h +++ b/src/libcore/configuration.h @@ -39,14 +39,16 @@ namespace GrumpyIRC virtual bool GetValueAsBool(const QString &key, bool none = false); virtual unsigned int GetValueAsUInt(const QString &key, unsigned int none = 0); virtual QString GetValueAsString(const QString &key, const QString &default_value = ""); + virtual QHash GetValueAsHash(const QString &key, const QHash &default_value = QHash()); virtual int GetValueAsInt(const QString &key, int none = 0); virtual float GetValueAsFloat(const QString &key, float none = 0); virtual void RemoveValue(const QString &key); virtual void SetValue(const QString &key, const QVariant &value); - virtual void SetValue(QString key, bool value); - virtual void SetValue(QString key, int value); - virtual void SetValue(QString key, unsigned int value); - virtual void SetValue(QString key, QString value); + virtual void SetValue(const QString &key, bool value); + virtual void SetValue(const QString &ey, int value); + virtual void SetValue(const QString &key, unsigned int value); + virtual void SetValue(const QString &key, const QString &value); + virtual void SetValue(const QString &ey, const QHash &hash); virtual void SetHomePath(const QString &path); // Extension config @@ -90,10 +92,11 @@ namespace GrumpyIRC inline QString mkExt(QString e, QString k) { return "ext_" + e + "/" + k; } }; - inline void Configuration::SetValue(QString key, bool value) { this->SetValue(key, QVariant(value)); } - inline void Configuration::SetValue(QString key, unsigned int value) { this->SetValue(key, QVariant(value)); } - inline void Configuration::SetValue(QString key, int value) { this->SetValue(key, QVariant(value)); } - inline void Configuration::SetValue(QString key, QString value) { this->SetValue(key, QVariant(value)); } + inline void Configuration::SetValue(const QString &key, bool value) { this->SetValue(key, QVariant(value)); } + inline void Configuration::SetValue(const QString &key, unsigned int value) { this->SetValue(key, QVariant(value)); } + inline void Configuration::SetValue(const QString &key, int value) { this->SetValue(key, QVariant(value)); } + inline void Configuration::SetValue(const QString &key, const QString &value) { this->SetValue(key, QVariant(value)); } + inline void Configuration::SetValue(const QString &key, const QHash &hash) { this->SetValue(key, QVariant(hash)); } } #endif // CONFIGURATION_H diff --git a/src/libcore/favorite.cpp b/src/libcore/favorite.cpp deleted file mode 100644 index 5e8ef6c..0000000 --- a/src/libcore/favorite.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//This program is free software: you can redistribute it and/or modify -//it under the terms of the GNU Lesser General Public License as published by -//the Free Software Foundation, either version 3 of the License, or -//(at your option) any later version. - -//This program is distributed in the hope that it will be useful, -//but WITHOUT ANY WARRANTY; without even the implied warranty of -//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -//GNU Lesser General Public License for more details. - -// Copyright (c) Petr Bena 2015 - -#include "favorite.h" - -using namespace GrumpyIRC; - -Favorite::Favorite() -{ - -} - diff --git a/src/libcore/identity.cpp b/src/libcore/identity.cpp new file mode 100644 index 0000000..647cda8 --- /dev/null +++ b/src/libcore/identity.cpp @@ -0,0 +1,83 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#include "identity.h" + +using namespace GrumpyIRC; + +int Identity::LastID = 0; +QHash Identity::Identities; + +void Identity::Clear() +{ + QList list = Identity::Identities.values(); + foreach (Identity *identity, list) + { + delete identity; + } + Identity::Identities.clear(); + Identity::LastID = 0; +} + +Identity::Identity(QHash hash) +{ + this->LoadHash(hash); + if (this->ID >= Identity::LastID) + Identity::LastID = this->ID + 1; +} + +Identity::Identity(QString nick, QString ident, QString real_name, QString away_msg, int id) +{ + if (id < 0) + { + this->ID = Identity::LastID++; + } else + { + this->ID = id; + if (id >= Identity::LastID) + Identity::LastID = id + 1; + } + + this->Nick = nick; + this->Ident = ident; + this->RealName = real_name; + this->AwayMessage = away_msg; +} + +QHash Identity::ToHash() +{ + QHash hash; + SERIALIZE(ID); + SERIALIZE(Nick); + SERIALIZE(Ident); + SERIALIZE(RealName); + SERIALIZE(AwayMessage); + return hash; +} + +void Identity::LoadHash(const QHash &hash) +{ + UNSERIALIZE_INT(ID); + UNSERIALIZE_STRING(Nick); + UNSERIALIZE_STRING(Ident); + UNSERIALIZE_STRING(RealName); + UNSERIALIZE_STRING(AwayMessage); +} + +QString Identity::ToString() +{ + QString result = this->Nick; + if (!this->Ident.isEmpty()) + result += "!" + this->Ident; + + return result; +} diff --git a/src/libcore/identity.h b/src/libcore/identity.h new file mode 100644 index 0000000..899fb51 --- /dev/null +++ b/src/libcore/identity.h @@ -0,0 +1,43 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#ifndef IDENTITY_H +#define IDENTITY_H + +#include +#include +#include "libcore_global.h" +#include "../libirc/libirc/serializableitem.h" + +namespace GrumpyIRC +{ + class LIBCORESHARED_EXPORT Identity : public libirc::SerializableItem + { + public: + static void Clear(); + static int LastID; + static QHash Identities; + + Identity(QHash hash); + Identity(QString nick, QString ident, QString real_name, QString away_msg = "", int id = -1); + QHash ToHash() override; + void LoadHash(const QHash &hash) override; + QString ToString(); + int ID; + QString Nick; + QString Ident; + QString RealName; + QString AwayMessage; + }; +} + +#endif // IDENTITY_H diff --git a/src/libcore/networkinfo.cpp b/src/libcore/networkinfo.cpp new file mode 100644 index 0000000..6a6adf6 --- /dev/null +++ b/src/libcore/networkinfo.cpp @@ -0,0 +1,92 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#include "networkinfo.h" +#include "identity.h" + +using namespace GrumpyIRC; + +QHash NetworkInfo::NetworksInfo; +int NetworkInfo::LastID = 0; + +void NetworkInfo::Clear() +{ + QList list = NetworkInfo::NetworksInfo.values(); + foreach (NetworkInfo *network_info, list) + { + delete network_info; + } + NetworkInfo::NetworksInfo.clear(); + NetworkInfo::LastID = 0; +} + +NetworkInfo::NetworkInfo(QString name, QString host, int port, int identity, bool ssl, int id) +{ + if (id < 0) + { + this->ID = NetworkInfo::LastID++; + } else + { + this->ID = id; + if (id >= NetworkInfo::LastID) + NetworkInfo::LastID = id + 1; + } + + this->NetworkName = name; + this->Hostname = host; + this->Port = port; + this->SSL = ssl; + this->PreferredIdentity = identity; +} + +NetworkInfo::NetworkInfo(const QHash &hash) +{ + this->LoadHash(hash); + if (this->ID >= LastID) + LastID = this->ID + 1; +} + +libirc::ServerAddress NetworkInfo::ToServerAddress() +{ + libirc::ServerAddress addr(this->Hostname, this->SSL, this->Port); + if (this->PreferredIdentity >= 0 && Identity::Identities.contains(this->PreferredIdentity)) + { + Identity *identity = Identity::Identities[this->PreferredIdentity]; + addr.SetNick(identity->Nick); + addr.SetIdent(identity->Ident); + } + return addr; +} + +QHash NetworkInfo::ToHash() +{ + QHash hash; + SERIALIZE(ID); + SERIALIZE(NetworkName); + SERIALIZE(Hostname); + SERIALIZE(PreferredIdentity); + SERIALIZE(SSL); + SERIALIZE(AutoReconnect); + SERIALIZE(Port); + return hash; +} + +void NetworkInfo::LoadHash(const QHash &hash) +{ + UNSERIALIZE_STRING(NetworkName); + UNSERIALIZE_INT(ID); + UNSERIALIZE_STRING(Hostname); + UNSERIALIZE_INT(PreferredIdentity); + UNSERIALIZE_BOOL(SSL); + UNSERIALIZE_INT(Port); + UNSERIALIZE_BOOL(AutoReconnect); +} diff --git a/src/libcore/networkinfo.h b/src/libcore/networkinfo.h new file mode 100644 index 0000000..3773026 --- /dev/null +++ b/src/libcore/networkinfo.h @@ -0,0 +1,47 @@ +//This program is free software: you can redistribute it and/or modify +//it under the terms of the GNU Lesser General Public License as published by +//the Free Software Foundation, either version 3 of the License, or +//(at your option) any later version. + +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU Lesser General Public License for more details. + +// Copyright (c) Petr Bena 2021 + +#ifndef NETWORKINFO_H +#define NETWORKINFO_H + +#include +#include +#include "libcore_global.h" +#include "../libirc/libirc/serveraddress.h" +#include "../libirc/libirc/serializableitem.h" +#include "../libirc/libirc/irc_standards.h" + +namespace GrumpyIRC +{ + class NetworkInfo : public libirc::SerializableItem + { + public: + static void Clear(); + static int LastID; + static QHash NetworksInfo; + + NetworkInfo(QString name, QString host, int port, int identity, bool ssl, int id = -1); + NetworkInfo(const QHash &hash); + libirc::ServerAddress ToServerAddress(); + QHash ToHash() override; + void LoadHash(const QHash &hash) override; + int ID; + QString NetworkName; + QString Hostname; + int Port = IRC_STANDARD_PORT; + int PreferredIdentity = -1; + bool AutoReconnect = false; + bool SSL = false; + }; +} + +#endif // NETWORKINFO_H diff --git a/src/libcore/query.h b/src/libcore/query.h index 8a66f28..239b801 100644 --- a/src/libcore/query.h +++ b/src/libcore/query.h @@ -20,6 +20,9 @@ namespace GrumpyIRC { class ScrollbackItem; + + //! This is unused work in progress + //! query for matching text, used by searching feature which is to be implemented class LIBCORESHARED_EXPORT Query : public libirc::SerializableItem { public: