1 | /*
|
---|
2 | * profiledlg.cpp - dialogs for manipulating profiles
|
---|
3 | * Copyright (C) 2001-2003 Justin Karneges
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * as published by the Free Software Foundation; either version 2
|
---|
8 | * of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this library; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include"profiledlg.h"
|
---|
22 | #include"common.h"
|
---|
23 |
|
---|
24 | #include<qlabel.h>
|
---|
25 | #include<qcombobox.h>
|
---|
26 | #include<qcheckbox.h>
|
---|
27 | #include<qpushbutton.h>
|
---|
28 | #include<qgroupbox.h>
|
---|
29 | #include<qlistbox.h>
|
---|
30 | #include<qinputdialog.h>
|
---|
31 | #include<qfile.h>
|
---|
32 | #include<qfileinfo.h>
|
---|
33 | #include<qbuttongroup.h>
|
---|
34 | #include<qwhatsthis.h>
|
---|
35 | #include"profiles.h"
|
---|
36 | #include"iconwidget.h"
|
---|
37 |
|
---|
38 | #include <qpainter.h>
|
---|
39 | class StretchLogoLabel : public QLabel
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | StretchLogoLabel(QPixmap pix, QWidget *label, const char *name = 0)
|
---|
43 | : QLabel((QWidget*)label->parent(), name)
|
---|
44 | {
|
---|
45 | setPixmap(pix);
|
---|
46 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
---|
47 | replaceWidget(label, this);
|
---|
48 | }
|
---|
49 |
|
---|
50 | void drawContents(QPainter *p)
|
---|
51 | {
|
---|
52 | p->drawTiledPixmap(0, 0, width(), height(), *pixmap());
|
---|
53 | }
|
---|
54 | };
|
---|
55 |
|
---|
56 | ProfileOpenDlg::ProfileOpenDlg(const QString &def, const VarList &_langs, const QString &curLang, QWidget *parent, const char *name)
|
---|
57 | :ProfileOpenUI(parent, name, TRUE)
|
---|
58 | {
|
---|
59 | setCaption(CAP(caption()));
|
---|
60 |
|
---|
61 | langs = _langs;
|
---|
62 |
|
---|
63 | // insert the logo
|
---|
64 | QPixmap logo = (QPixmap)IconsetFactory::icon("psi/psiLogo").pixmap();
|
---|
65 | lb_logo->setPixmap(logo);
|
---|
66 | lb_logo->setFixedSize(logo.width(), logo.height());
|
---|
67 | lb_logo->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
|
---|
68 | //setFixedWidth(logo->width());
|
---|
69 |
|
---|
70 | QImage logoImg = logo.convertToImage();
|
---|
71 |
|
---|
72 | QPixmap tmp;
|
---|
73 | tmp.convertFromImage( logoImg.copy(0, 0, 1, logoImg.height()) );
|
---|
74 | StretchLogoLabel *stretch = new StretchLogoLabel(tmp, lb_left);
|
---|
75 |
|
---|
76 | tmp.convertFromImage( logoImg.copy(logoImg.width()-1, 0, 1, logoImg.height()) );
|
---|
77 | stretch = new StretchLogoLabel(tmp, lb_right);
|
---|
78 |
|
---|
79 | // setup signals
|
---|
80 | connect(pb_open, SIGNAL(clicked()), SLOT(accept()));
|
---|
81 | connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
|
---|
82 | connect(pb_profiles, SIGNAL(clicked()), SLOT(manageProfiles()));
|
---|
83 | connect(cb_lang, SIGNAL(activated(int)), SLOT(langChange(int)));
|
---|
84 |
|
---|
85 | int x = 0;
|
---|
86 | langSel = x;
|
---|
87 | for(VarList::ConstIterator it = langs.begin(); it != langs.end(); ++it) {
|
---|
88 | cb_lang->insertItem((*it).data());
|
---|
89 | if((curLang.isEmpty() && x == 0) || (curLang == (*it).key())) {
|
---|
90 | cb_lang->setCurrentItem(x);
|
---|
91 | langSel = x;
|
---|
92 | }
|
---|
93 | ++x;
|
---|
94 | }
|
---|
95 |
|
---|
96 | // QWhatsThis helpers
|
---|
97 | QWhatsThis::add(cb_profile,
|
---|
98 | tr("Select a profile to open from this list."));
|
---|
99 | QWhatsThis::add(cb_lang,
|
---|
100 | tr("Select a language you would like Psi to use from this "
|
---|
101 | "list. You can download extra language packs from the Psi homepage."));
|
---|
102 | QWhatsThis::add(ck_auto,
|
---|
103 | tr("Automatically open this profile when Psi is started. Useful if "
|
---|
104 | "you only have one profile."));
|
---|
105 |
|
---|
106 | reload(def);
|
---|
107 | }
|
---|
108 |
|
---|
109 | ProfileOpenDlg::~ProfileOpenDlg()
|
---|
110 | {
|
---|
111 | }
|
---|
112 |
|
---|
113 | void ProfileOpenDlg::reload(const QString &choose)
|
---|
114 | {
|
---|
115 | QStringList list = getProfilesList();
|
---|
116 |
|
---|
117 | cb_profile->clear();
|
---|
118 |
|
---|
119 | if(list.count() == 0) {
|
---|
120 | gb_open->setEnabled(FALSE);
|
---|
121 | pb_open->setEnabled(FALSE);
|
---|
122 | pb_profiles->setFocus();
|
---|
123 | }
|
---|
124 | else {
|
---|
125 | int x = 0;
|
---|
126 | for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
---|
127 | cb_profile->insertItem(*it);
|
---|
128 | if((choose.isEmpty() && x == 0) || (choose == *it)) {
|
---|
129 | cb_profile->setCurrentItem(x);
|
---|
130 | }
|
---|
131 | ++x;
|
---|
132 | }
|
---|
133 |
|
---|
134 | gb_open->setEnabled(TRUE);
|
---|
135 | pb_open->setEnabled(TRUE);
|
---|
136 | pb_open->setFocus();
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | void ProfileOpenDlg::manageProfiles()
|
---|
141 | {
|
---|
142 | ProfileManageDlg *w = new ProfileManageDlg(cb_profile->currentText(), this);
|
---|
143 | w->exec();
|
---|
144 | QString last = w->lbx_profiles->text(w->lbx_profiles->currentItem());
|
---|
145 | delete w;
|
---|
146 |
|
---|
147 | reload(last);
|
---|
148 | }
|
---|
149 |
|
---|
150 | void ProfileOpenDlg::langChange(int x)
|
---|
151 | {
|
---|
152 | if(x == langSel)
|
---|
153 | return;
|
---|
154 | langSel = x;
|
---|
155 |
|
---|
156 | VarList::Iterator it = langs.findByNum(x);
|
---|
157 | newLang = (*it).key();
|
---|
158 | done(10);
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | ProfileManageDlg::ProfileManageDlg(const QString &choose, QWidget *parent, const char *name)
|
---|
163 | :ProfileManageUI(parent, name, TRUE)
|
---|
164 | {
|
---|
165 | setCaption(CAP(caption()));
|
---|
166 |
|
---|
167 | // setup signals
|
---|
168 | connect(pb_new, SIGNAL(clicked()), SLOT(slotProfileNew()));
|
---|
169 | connect(pb_rename, SIGNAL(clicked()), SLOT(slotProfileRename()));
|
---|
170 | connect(pb_delete, SIGNAL(clicked()), SLOT(slotProfileDelete()));
|
---|
171 | connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
|
---|
172 | connect(lbx_profiles, SIGNAL(highlighted(int)), SLOT(updateSelection()));
|
---|
173 |
|
---|
174 | // load the listing
|
---|
175 | QStringList list = getProfilesList();
|
---|
176 | int x = 0;
|
---|
177 | for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
---|
178 | lbx_profiles->insertItem(*it);
|
---|
179 | if(*it == choose)
|
---|
180 | lbx_profiles->setCurrentItem(x);
|
---|
181 | ++x;
|
---|
182 | }
|
---|
183 |
|
---|
184 | updateSelection();
|
---|
185 | }
|
---|
186 |
|
---|
187 | void ProfileManageDlg::slotProfileNew()
|
---|
188 | {
|
---|
189 | QString name;
|
---|
190 |
|
---|
191 | ProfileNewDlg *w = new ProfileNewDlg(this);
|
---|
192 | int r = w->exec();
|
---|
193 | if(r == QDialog::Accepted) {
|
---|
194 | name = w->name;
|
---|
195 |
|
---|
196 | lbx_profiles->insertItem(name);
|
---|
197 | lbx_profiles->setCurrentItem(lbx_profiles->count()-1);
|
---|
198 | }
|
---|
199 | delete w;
|
---|
200 |
|
---|
201 | if(r == QDialog::Accepted) {
|
---|
202 | close();
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | void ProfileManageDlg::slotProfileRename()
|
---|
207 | {
|
---|
208 | int x = lbx_profiles->currentItem();
|
---|
209 | if(x == -1)
|
---|
210 | return;
|
---|
211 |
|
---|
212 | QString oldname = lbx_profiles->text(x);
|
---|
213 | QString name;
|
---|
214 |
|
---|
215 | while(1) {
|
---|
216 | bool ok = FALSE;
|
---|
217 | name = QInputDialog::getText(CAP(tr("Rename Profile")), tr("Please enter a new name for the profile. Keep it simple.\nOnly use letters or numbers. No punctuation or spaces."), QLineEdit::Normal, name, &ok, this);
|
---|
218 | if(!ok)
|
---|
219 | return;
|
---|
220 |
|
---|
221 | if(profileExists(name)) {
|
---|
222 | QMessageBox::information(this, CAP(tr("Rename Profile")), tr("There is already another profile with this name. Please choose another."));
|
---|
223 | continue;
|
---|
224 | }
|
---|
225 | else if(!profileRename(oldname, name)) {
|
---|
226 | QMessageBox::information(this, CAP(tr("Rename Profile")), tr("Unable to rename the profile. Please do not use any special characters."));
|
---|
227 | continue;
|
---|
228 | }
|
---|
229 | break;
|
---|
230 | }
|
---|
231 |
|
---|
232 | lbx_profiles->changeItem(name, x);
|
---|
233 | }
|
---|
234 |
|
---|
235 | void ProfileManageDlg::slotProfileDelete()
|
---|
236 | {
|
---|
237 | int x = lbx_profiles->currentItem();
|
---|
238 | if(x == -1)
|
---|
239 | return;
|
---|
240 | QString name = lbx_profiles->text(x);
|
---|
241 | QString path = g.pathProfiles + "/" + name;
|
---|
242 |
|
---|
243 | // prompt first
|
---|
244 | int r = QMessageBox::warning(this,
|
---|
245 | CAP(tr("Delete Profile")),
|
---|
246 | tr(
|
---|
247 | "<qt>Are you sure you want to delete the \"<b>%1</b>\" profile? "
|
---|
248 | "This will delete all of the profile's message history as well as associated settings!</qt>"
|
---|
249 | ).arg(name),
|
---|
250 | tr("No, I changed my mind"),
|
---|
251 | tr("Delete it!"));
|
---|
252 |
|
---|
253 | if(r != 1)
|
---|
254 | return;
|
---|
255 |
|
---|
256 | r = QMessageBox::information(this,
|
---|
257 | CAP(tr("Delete Profile")),
|
---|
258 | tr(
|
---|
259 | "<qt>As a precaution, you are being asked one last time if this is what you really want. "
|
---|
260 | "The following folder will be deleted!<br><br>\n"
|
---|
261 | " <b>%1</b><br><br>\n"
|
---|
262 | "Proceed?"
|
---|
263 | ).arg(path),
|
---|
264 | tr("&No"),
|
---|
265 | tr("&Yes"));
|
---|
266 |
|
---|
267 | if(r == 1) {
|
---|
268 | if(!profileDelete(path)) {
|
---|
269 | QMessageBox::critical(this, CAP("Error"), tr("Unable to delete the folder completely. Ensure you have the proper permission."));
|
---|
270 | return;
|
---|
271 | }
|
---|
272 |
|
---|
273 | lbx_profiles->removeItem(x);
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | void ProfileManageDlg::updateSelection()
|
---|
278 | {
|
---|
279 | int x = lbx_profiles->currentItem();
|
---|
280 |
|
---|
281 | if(x == -1) {
|
---|
282 | pb_rename->setEnabled(FALSE);
|
---|
283 | pb_delete->setEnabled(FALSE);
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | pb_rename->setEnabled(TRUE);
|
---|
287 | pb_delete->setEnabled(TRUE);
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | ProfileNewDlg::ProfileNewDlg(QWidget *parent, const char *name)
|
---|
293 | :ProfileNewUI(parent, name, TRUE)
|
---|
294 | {
|
---|
295 | setCaption(CAP(caption()));
|
---|
296 |
|
---|
297 | bg_defAct->setButton(bg_defAct->id((QButton *)rb_chat));
|
---|
298 | le_name->setFocus();
|
---|
299 |
|
---|
300 | connect(pb_create, SIGNAL(clicked()), SLOT(slotCreate()));
|
---|
301 | connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
|
---|
302 | connect(le_name, SIGNAL(textChanged(const QString &)), SLOT(nameModified()));
|
---|
303 |
|
---|
304 | nameModified();
|
---|
305 | }
|
---|
306 |
|
---|
307 | void ProfileNewDlg::slotCreate()
|
---|
308 | {
|
---|
309 | name = le_name->text();
|
---|
310 |
|
---|
311 | if(profileExists(name)) {
|
---|
312 | QMessageBox::information(this, CAP(tr("New Profile")), tr("There is already an existing profile with this name. Please choose another."));
|
---|
313 | return;
|
---|
314 | }
|
---|
315 |
|
---|
316 | if(!profileNew(name)) {
|
---|
317 | QMessageBox::information(this, CAP(tr("New Profile")), tr("Unable to create the profile. Please do not use any special characters."));
|
---|
318 | return;
|
---|
319 | }
|
---|
320 |
|
---|
321 | // save config
|
---|
322 | UserProfile p;
|
---|
323 | p.prefs.defaultAction = bg_defAct->selected() == (QButton *)rb_message ? 0: 1;
|
---|
324 | p.prefs.useEmoticons = ck_useEmoticons->isChecked();
|
---|
325 | p.toFile(pathToProfileConfig(name));
|
---|
326 |
|
---|
327 | accept();
|
---|
328 | }
|
---|
329 |
|
---|
330 | void ProfileNewDlg::nameModified()
|
---|
331 | {
|
---|
332 | pb_create->setEnabled(!le_name->text().isEmpty());
|
---|
333 | }
|
---|