# HG changeset patch # User Goffi # Date 1312792223 -7200 # Node ID fee291c8d42a94eebac27393306dd2a2ddbb1686 # Parent 2e015f69f756778490cea48ff77e8de9ecd4f360 settings: profiles management first draft diff -r 2e015f69f756 -r fee291c8d42a bellaciao.cpp --- a/bellaciao.cpp Sat Aug 06 15:38:00 2011 +0200 +++ b/bellaciao.cpp Mon Aug 08 10:30:23 2011 +0200 @@ -17,7 +17,7 @@ */ #include "bellaciao.h" -#include "parameters.h" +#include "settings.h" Bellaciao::Bellaciao() :QMainWindow(0) @@ -26,10 +26,14 @@ //Ui setupUi(this); + const QString & media_dir = m_bridge->getConfig("", "media_dir"); + setWindowIcon(QIcon(media_dir+"/icons/apps/32/sat.png")); m_contactList = new ContactList(this); + //Signals & Slots - connect(actionParameters, SIGNAL(triggered()), this, SLOT(showParameters())); + connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings())); + connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit())); addDockWidget(Qt::LeftDockWidgetArea, m_contactList); @@ -39,7 +43,6 @@ QList menus = m_bridge->getMenus(); foreach(const MenuT &menu, menus) qDebug() << menu.name; - StringDict waiting=m_bridge->getWaitingSub("jabberfr"); QList contacts = m_bridge->getContacts("jabberfr"); @@ -50,26 +53,26 @@ } -void Bellaciao::disconnect() +void Bellaciao::quit() { if ( QMessageBox::question ( this, - tr("Disconnect?"), - tr("Do you really want to disconnect ?"), + tr("Quit?"), + tr("Do you really want to quit ?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes ) { - m_bridge->disconnect("jabberfr"); + qApp->quit(); } } -void Bellaciao::showParameters() +void Bellaciao::showSettings() { - qDebug("Show parameters"); - ParametersWin *params = new ParametersWin(); - params->show(); + qDebug("Show settings"); + Settings::getDialog()->show(); + Settings::getDialog()->raise(); } void Bellaciao::on_actionToggle_fullscreen_triggered() diff -r 2e015f69f756 -r fee291c8d42a bellaciao.h --- a/bellaciao.h Sat Aug 06 15:38:00 2011 +0200 +++ b/bellaciao.h Mon Aug 08 10:30:23 2011 +0200 @@ -34,8 +34,8 @@ private slots: - void disconnect(); - void showParameters(); + void quit(); + void showSettings(); void on_actionToggle_fullscreen_triggered(); private: diff -r 2e015f69f756 -r fee291c8d42a bellaciao.pro --- a/bellaciao.pro Sat Aug 06 15:38:00 2011 +0200 +++ b/bellaciao.pro Mon Aug 08 10:30:23 2011 +0200 @@ -7,8 +7,9 @@ DEPENDPATH += . INCLUDEPATH += . QT += dbus +CONFIG += debug # Input -HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h parameters.h -SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp parameters.cpp -FORMS += main_win.ui parameters_win.ui +HEADERS += bellaciao.h contact_list.h dbus_bridge.h dbus_types.h bridge.h settings.h session.h +SOURCES += main.cpp bellaciao.cpp contact_list.cpp dbus_bridge.cpp dbus_types.cpp bridge.cpp settings.cpp session.cpp +FORMS += main_win.ui settings.ui diff -r 2e015f69f756 -r fee291c8d42a main_win.ui --- a/main_win.ui Sat Aug 06 15:38:00 2011 +0200 +++ b/main_win.ui Mon Aug 08 10:30:23 2011 +0200 @@ -47,7 +47,7 @@ General - + @@ -55,9 +55,9 @@ - + - Parameters + Settings diff -r 2e015f69f756 -r fee291c8d42a parameters.cpp --- a/parameters.cpp Sat Aug 06 15:38:00 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* -Bellaciao: a Salut à Toi frontend -Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero 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 Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#include "parameters.h" - -ParametersWin :: ParametersWin(QWidget *parent) - : QWidget(parent) -{ - setupUi(this); - - //We fill the profiles list - m_bridge = Bridge::getBridge(); - const QList& profiles = m_bridge->getProfilesList(); - foreach(const QString& profile, profiles) - new QListWidgetItem(profile, profileList); - -} - diff -r 2e015f69f756 -r fee291c8d42a parameters.h --- a/parameters.h Sat Aug 06 15:38:00 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* -Bellaciao: a Salut à Toi frontend -Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero 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 Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ - -#ifndef PARAMETERS_H -#define PARAMETERS_H - - -#include -#include "ui_parameters_win.h" -#include "bridge.h" - -class ParametersWin : public QWidget, private Ui::ParametersWin -{ - Q_OBJECT - - public: - ParametersWin(QWidget *parent = 0); - - private: - Bridge* m_bridge; - -}; - - - - -#endif diff -r 2e015f69f756 -r fee291c8d42a parameters_win.ui --- a/parameters_win.ui Sat Aug 06 15:38:00 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ - - - ParametersWin - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - - 0 - - - - Profiles - - - - - - - - - - - - - - - - - - jid - - - - - - - - - - Password - - - - - - - - - - - - - Custom Server - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Server - - - - - - - - - - Port - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - - - - New - - - false - - - false - - - - - - - Delete - - - - - - - Set as default - - - - - - - - - - - Contact list layout - - - - - - - - - diff -r 2e015f69f756 -r fee291c8d42a session.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/session.cpp Mon Aug 08 10:30:23 2011 +0200 @@ -0,0 +1,36 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero 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 Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "session.h" + +Session* Session::_instance = 0; + + +Session::Session() +{ +} + +Session* Session::getSession() +{ + if (_instance == 0) + _instance = new Session; + + return _instance; + +} + diff -r 2e015f69f756 -r fee291c8d42a session.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/session.h Mon Aug 08 10:30:23 2011 +0200 @@ -0,0 +1,36 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero 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 Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef SESSION_H +#define SESSION_H + +class Session +{ +public: + static Session* getSession(); + +protected: + Session(); + +private: + static Session* _instance; +}; + + + +#endif diff -r 2e015f69f756 -r fee291c8d42a settings.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/settings.cpp Mon Aug 08 10:30:23 2011 +0200 @@ -0,0 +1,175 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero 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 Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#include "settings.h" + +using namespace Qt; + +Settings* Settings::_instance = 0; + +ProfileListWidgetItem::ProfileListWidgetItem(const QString & profile, QListWidget * parent, bool isDefault) + :QListWidgetItem(profile, parent) +{ + m_profile = profile; + if (isDefault) { + setText(text() + QObject::tr(" (default)")); + QFont _font = font(); + _font.setWeight(QFont::Bold); + setFont(_font); + } + +} + +const QString& ProfileListWidgetItem::getProfile() +{ + return m_profile; +} + +Settings::Settings(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + this->setAttribute(WA_DeleteOnClose); + + //We fill the profiles list + m_bridge = Bridge::getBridge(); + const QList& profiles = m_bridge->getProfilesList(); + const QString& default_profile = m_bridge->getProfileName("@DEFAULT@"); + foreach(const QString& profile, profiles) { + ProfileListWidgetItem *item = new ProfileListWidgetItem(profile, profileList, profile==default_profile); + item->setFlags(item->flags() | ItemIsUserCheckable); + item->setCheckState(Checked); + } + + connect(profileList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(profileChanged(QListWidgetItem*))); + connect(profileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(profileCurrentChanged(QListWidgetItem*, QListWidgetItem*))); + + //Profiles manipulation buttons + connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); + + //Confirmation buttons + connect(buttonsGroupConfirm, SIGNAL(accepted()), this, SLOT(saveSettings())); + connect(buttonsGroupConfirm, SIGNAL(rejected()), this, SLOT(cancelSettings())); +} + +Settings::~Settings() +{ + _instance = 0; +} + +Settings* Settings::getDialog() { + if (_instance == 0) { + _instance = new Settings; + } + + return _instance; +} + +//Profile settings slots +void Settings::profileChanged(QListWidgetItem* item) +{ + qDebug() << "profileChanged"; +} + +void Settings::profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous) +{ + if (!current) { + profileData->setEnabled(false); + customServerGroup->setEnabled(false); + customServerGroup->setChecked(false); + buttonDelete->setEnabled(false); + buttonSetDefault->setEnabled(false); + jidField->clear(); + passwordField->clear(); + serverField->clear(); + portField->clear(); + return; + } + + ProfileListWidgetItem *item = dynamic_cast(current); + + profileData->setEnabled(true); + customServerGroup->setEnabled(true); + jidField->setEnabled(true); + passwordField->setEnabled(true); + buttonDelete->setEnabled(true); + buttonSetDefault->setEnabled(true); + const QString& jid = m_bridge->getParamA("JabberID", "Connection", "value", item->getProfile()); + const QString& password = m_bridge->getParamA("Password", "Connection", "value", item->getProfile()); + jidField->setText(jid); + passwordField->setText(password); +} + + +void Settings::on_buttonNew_clicked() { + bool ok; + QString name = QInputDialog::getText(this, tr("New profile"), tr("Please enter profile name: "), QLineEdit::Normal, QString(), &ok); + if (ok && !name.isEmpty()) { + int success = m_bridge->createProfile(name); + ProfileListWidgetItem *item; + + switch (success) { + case 0: //success + item = new ProfileListWidgetItem(name, profileList); + item->setFlags(item->flags() | ItemIsUserCheckable); + item->setCheckState(Checked); + break; + case 1: //profile name conflict + QMessageBox::warning(this, tr("Profile name conflict"), tr("A profile with this name already exists. Please choose an other name")); + break; + default: + QMessageBox::warning(this, tr("Profile creation error"), tr("Can't create profile")); + + } + } +} + + +void Settings::on_buttonDelete_clicked() { + ProfileListWidgetItem *item = dynamic_cast(profileList->currentItem()); + + if ( QMessageBox::question ( + this, + tr("Delete profile?"), + tr("Do you really want to delete profile \"%1\" ?").arg(item->getProfile()), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No + ) == QMessageBox::Yes + ) + { + int success = m_bridge->deleteProfile(item->getProfile()); + if (success==0) + delete(item); + else + QMessageBox::warning(this, tr("Profile deletion error"), tr("Can't delete profile")); + } + + +} + + +//Global settings slots +void Settings::saveSettings() +{ +} + +void Settings::cancelSettings() +{ + this->close(); +} diff -r 2e015f69f756 -r fee291c8d42a settings.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/settings.h Mon Aug 08 10:30:23 2011 +0200 @@ -0,0 +1,65 @@ +/* +Bellaciao: a Salut à Toi frontend +Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero 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 Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +#ifndef SETTINGS_H +#define SETTINGS_H + + +#include +#include "ui_settings.h" +#include "bridge.h" + +class ProfileListWidgetItem : public QListWidgetItem +{ + + public: + ProfileListWidgetItem(const QString & profile, QListWidget * parent, bool isDefault=false); + const QString& getProfile(); + private: + QString m_profile; +}; + +class Settings : public QWidget, private Ui::SettingsDlg +{ + Q_OBJECT + + public: + ~Settings(); + static Settings* getDialog(); + + + private slots: + void profileChanged(QListWidgetItem* item); + void profileCurrentChanged(QListWidgetItem* current, QListWidgetItem* previous); + void on_buttonNew_clicked(); + void on_buttonDelete_clicked(); + void saveSettings(); + void cancelSettings(); + + protected: + Settings(QWidget *parent = 0); + + private: + static Settings* _instance; + Bridge* m_bridge; + +}; + + + +#endif diff -r 2e015f69f756 -r fee291c8d42a settings.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/settings.ui Mon Aug 08 10:30:23 2011 +0200 @@ -0,0 +1,218 @@ + + + SettingsDlg + + + + 0 + 0 + 629 + 360 + + + + Form + + + + + + 0 + + + + Profiles + + + + + + + + + + + + Check profiles you want to use + + + Qt::AlignCenter + + + + + + + true + + + + + + + + + + + + + false + + + + + + jid + + + + + + + false + + + + + + + Password + + + + + + + false + + + QLineEdit::Password + + + + + + + + + + false + + + Custom Server + + + true + + + false + + + + QFormLayout::ExpandingFieldsGrow + + + + + Server + + + + + + + + + + Port + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + + + New + + + false + + + false + + + + + + + false + + + Delete + + + + + + + false + + + Set as default + + + + + + + + + + + Contact list layout + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + +