-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsdialog.cpp
129 lines (104 loc) · 4.1 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/************************************************
*
* Copyright © 2009-2010 Florian Staudacher
*
*
* This file is part of FSugar.
*
* FSugar 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.
*
* FSugar 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FSugar. If not, see <http://www.gnu.org/licenses/>.
*
***********************************************/
#include <QtGui>
#include "settingsdialog.h"
#include "sugarsettings.h"
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent)
{
settings = SugarSettings::getInstance();
userChange = false;
QVBoxLayout *layout = new QVBoxLayout();
QGroupBox *sugarBox = new QGroupBox(tr("SugarCRM Konfiguration"));
QGroupBox *calBox = new QGroupBox(tr("Kalender Konfiguration"));
QFormLayout *settingsForm = new QFormLayout();
QFormLayout *calForm = new QFormLayout();
QHBoxLayout *buttons = new QHBoxLayout();
QLabel *header = new QLabel(tr("Einstellungen"));
header->setProperty("heading", true);
settingsSaved = new QLabel(tr("Einstellungen gespeichert."));
settingsSaved->hide();
hostEdit = new QLineEdit(settings->sugarHost);
pathEdit = new QLineEdit(settings->sugarPath);
calPathEdit = new QLineEdit(settings->calendarUrl);
useSslEdit = new QCheckBox();
useSslEdit->setChecked(settings->useSsl);
usernameEdit = new QLineEdit(settings->sugarUser);
passwordEdit = new QLineEdit(settings->sugarPass);
passwordEdit->setEchoMode(QLineEdit::Password);
QPushButton *saveBtn = new QPushButton(QIcon(":save.png"), tr("Speichern"));
settingsForm->addRow(tr("Hostname"), hostEdit);
settingsForm->addRow(tr("Pfad"), pathEdit);
settingsForm->addRow(tr("Verschl\374sselung"), useSslEdit);
settingsForm->addRow(tr("Benutzername"), usernameEdit);
settingsForm->addRow(tr("Passwort"), passwordEdit);
sugarBox->setLayout(settingsForm);
calForm->addRow(tr("Adresse"), calPathEdit);
calBox->setLayout(calForm);
buttons->addStretch(5);
buttons->addWidget(settingsSaved);
buttons->addWidget(saveBtn);
layout->addWidget(header);
QLabel *saveNote = new QLabel(tr("Um alle Aenderungen zu uebernehmen,\nmuss das Programm neu gestartet werden!"));
saveNote->setAlignment(Qt::AlignCenter);
layout->addWidget(saveNote, 1, Qt::AlignCenter);
layout->addWidget(sugarBox);
layout->addWidget(calBox);
layout->addStretch(3);
layout->addLayout(buttons);
setLayout(layout);
connect(saveBtn, SIGNAL(pressed()),
this, SLOT(saveSettings()));
connect(settings, SIGNAL(settingsChanged()),
this, SLOT(showSettingsUpdated()));
}
void SettingsDialog::saveSettings()
{
userChange = true;
qDebug() << "[settings] saving settings";
settings->m_settings->setValue("SugarCrm/hostname", hostEdit->text());
settings->m_settings->setValue("SugarCrm/path", pathEdit->text());
settings->m_settings->setValue("SugarCrm/useSsl", useSslEdit->isChecked());
settings->m_settings->setValue("SugarCrm/username", usernameEdit->text());
// TODO: "encrypt" password
// http://lists.trolltech.com/qt-interest/2007-11/thread00001-0.html
settings->m_settings->setValue("SugarCrm/password", passwordEdit->text());
settings->m_settings->setValue("Calendar/url", calPathEdit->text());
settings->makeUpdate();
}
void SettingsDialog::showSettingsUpdated()
{
if( userChange ) {
settingsSaved->show();
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(settingsSaved);
settingsSaved->setGraphicsEffect(effect);
QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity");
anim->setStartValue(1.0);
anim->setEndValue(0.01);
anim->setDuration(2000);
connect(anim, SIGNAL(finished()),
settingsSaved, SLOT(hide()));
anim->start();
userChange = false;
}
}