~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to src/gui/dialogs/configdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file configdialog.cpp
 
3
 * Configuration dialog.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 17 Sep 2003
 
8
 *
 
9
 * Copyright (C) 2003-2007  Urs Fleisch
 
10
 *
 
11
 * This file is part of Kid3.
 
12
 *
 
13
 * Kid3 is free software; you can redistribute it and/or modify
 
14
 * it under the terms of the GNU General Public License as published by
 
15
 * the Free Software Foundation; either version 2 of the License, or
 
16
 * (at your option) any later version.
 
17
 *
 
18
 * Kid3 is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
 */
 
26
 
 
27
#include "configdialog.h"
 
28
#include "config.h"
 
29
#ifdef CONFIG_USE_KDE
 
30
#include <kconfig.h>
 
31
#endif
 
32
 
 
33
#include <cstring>
 
34
#include <QLayout>
 
35
#include <QPushButton>
 
36
#include <QLabel>
 
37
#include <QString>
 
38
#include <QCheckBox>
 
39
#include <QComboBox>
 
40
#include <QLineEdit>
 
41
#include <QTabWidget>
 
42
#include <QSpinBox>
 
43
#include "qtcompatmac.h"
 
44
#include <QVBoxLayout>
 
45
#include <QHBoxLayout>
 
46
#include <QGroupBox>
 
47
#include <QStringListModel>
 
48
#ifndef CONFIG_USE_KDE
 
49
#include <QApplication>
 
50
#include <QFontDialog>
 
51
#include <QStyleFactory>
 
52
#endif
 
53
 
 
54
#include "formatconfig.h"
 
55
#include "formatbox.h"
 
56
#include "miscconfig.h"
 
57
#include "stringlistedit.h"
 
58
#include "configtable.h"
 
59
#include "commandstablemodel.h"
 
60
#include "contexthelp.h"
 
61
 
 
62
enum { TextEncodingV1Latin1Index = 13 };
 
63
 
 
64
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
65
/**
 
66
 * Remove aliases in braces from text encoding combo box entry.
 
67
 *
 
68
 * @param comboEntry text encoding combo box entry
 
69
 *
 
70
 * @return codec name.
 
71
 */
 
72
static QString getTextEncodingV1CodecName(const QString& comboEntry)
 
73
{
 
74
  int braceIdx = comboEntry.indexOf(" (");
 
75
  return braceIdx == -1 ? comboEntry : comboEntry.left(braceIdx);
 
76
}
 
77
#endif
 
78
 
 
79
/**
 
80
 * Constructor.
 
81
 *
 
82
 * @param parent  parent widget
 
83
 * @param caption dialog title
 
84
 */
 
85
#ifdef CONFIG_USE_KDE
 
86
ConfigDialog::ConfigDialog(QWidget* parent, QString& caption,
 
87
                           KConfigSkeleton* configSkeleton) :
 
88
  KConfigDialog(parent, "configure", configSkeleton)
 
89
#else
 
90
ConfigDialog::ConfigDialog(QWidget* parent, QString& caption) :
 
91
  QDialog(parent)
 
92
#endif
 
93
{
 
94
  setObjectName("ConfigDialog");
 
95
  setWindowTitle(caption);
 
96
  setSizeGripEnabled(true);
 
97
#ifndef CONFIG_USE_KDE
 
98
  QVBoxLayout* topLayout = new QVBoxLayout(this);
 
99
  topLayout->setSpacing(6);
 
100
  topLayout->setMargin(6);
 
101
  QTabWidget* tabWidget = new QTabWidget(this);
 
102
#endif
 
103
 
 
104
  QWidget* tagsPage = new QWidget;
 
105
  if (tagsPage) {
 
106
    QVBoxLayout* vlayout = new QVBoxLayout(tagsPage);
 
107
    if (vlayout) {
 
108
      vlayout->setMargin(6);
 
109
      vlayout->setSpacing(6);
 
110
      QGroupBox* v1GroupBox = new QGroupBox(i18n("ID3v1"), tagsPage);
 
111
      QGridLayout* v1GroupBoxLayout = new QGridLayout(v1GroupBox);
 
112
      v1GroupBoxLayout->setMargin(2);
 
113
      v1GroupBoxLayout->setSpacing(4);
 
114
      if (v1GroupBox) {
 
115
        m_markTruncationsCheckBox = new QCheckBox(i18n("&Mark truncated fields"), v1GroupBox);
 
116
        v1GroupBoxLayout->addWidget(m_markTruncationsCheckBox, 0, 0, 1, 2);
 
117
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
118
        QLabel* textEncodingV1Label = new QLabel(i18n("Text &encoding:"), v1GroupBox);
 
119
        m_textEncodingV1ComboBox = new QComboBox(v1GroupBox);
 
120
#endif
 
121
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
122
        if (textEncodingV1Label && m_textEncodingV1ComboBox) {
 
123
          static const char* const codecs[] = {
 
124
            "Apple Roman (macintosh)",
 
125
            "Big5",
 
126
            "big5-0",
 
127
            "Big5-HKSCS",
 
128
            "big5hkscs-0",
 
129
            "EUC-JP",
 
130
            "EUC-KR",
 
131
            "GB18030",
 
132
            "GBK (windows-936)",
 
133
            "hp-roman8",
 
134
            "IBM850",
 
135
            "IBM866",
 
136
            "ISO-2022-JP (JIS7)",
 
137
            "ISO-8859-1 (latin1)",
 
138
            "ISO-8859-2 (latin2)",
 
139
            "ISO-8859-3 (latin3)",
 
140
            "ISO-8859-4 (latin4)",
 
141
            "ISO-8859-5 (cyrillic)",
 
142
            "ISO-8859-6 (arabic)",
 
143
            "ISO-8859-7 (greek)",
 
144
            "ISO-8859-8 (hebrew)",
 
145
            "ISO-8859-9 (latin5)",
 
146
            "ISO-8859-10 (latin6)",
 
147
            "ISO-8859-13 (baltic)",
 
148
            "ISO-8859-14 (latin8, iso-celtic)",
 
149
            "ISO-8859-15 (latin9)",
 
150
            "ISO-8859-16 (latin10)",
 
151
            "ISO-10646-UCS-2 (UTF-16)",
 
152
            "Iscii-Bng",
 
153
            "Iscii-Dev",
 
154
            "Iscii-Gjr",
 
155
            "Iscii-Knd",
 
156
            "Iscii-Mlm",
 
157
            "Iscii-Ori",
 
158
            "Iscii-Pnj",
 
159
            "Iscii-Tlg",
 
160
            "Iscii-Tml",
 
161
            "jisx0201*-0",
 
162
            "KOI8-R",
 
163
            "KOI8-U",
 
164
            "ksc5601.1987-0",
 
165
            "mulelao-1",
 
166
            "Shift_JIS (SJIS, MS_Kanji)",
 
167
            "TIS-620 (ISO 8859-11)",
 
168
            "TSCII",
 
169
            "UTF-8",
 
170
            "windows-1250",
 
171
            "windows-1251",
 
172
            "windows-1252",
 
173
            "windows-1253",
 
174
            "windows-1254",
 
175
            "windows-1255",
 
176
            "windows-1256",
 
177
            "windows-1257",
 
178
            "windows-1258",
 
179
            "WINSAMI2 (WS2)",
 
180
            0
 
181
          };
 
182
          Q_ASSERT(std::strcmp(codecs[TextEncodingV1Latin1Index], "ISO-8859-1 (latin1)") == 0);
 
183
          const char* const* str = codecs;
 
184
          m_textEncodingV1List.clear();
 
185
          while (*str) {
 
186
            m_textEncodingV1List += *str++;
 
187
          }
 
188
          m_textEncodingV1ComboBox->addItems(m_textEncodingV1List);
 
189
          m_textEncodingV1ComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
 
190
          textEncodingV1Label->setBuddy(m_textEncodingV1ComboBox);
 
191
          v1GroupBoxLayout->addWidget(textEncodingV1Label, 1, 0);
 
192
          v1GroupBoxLayout->addWidget(m_textEncodingV1ComboBox, 1, 1);
 
193
        }
 
194
#endif
 
195
        vlayout->addWidget(v1GroupBox);
 
196
      }
 
197
      QGroupBox* v2GroupBox = new QGroupBox(i18n("ID3v2"), tagsPage);
 
198
      QGridLayout* v2GroupBoxLayout = new QGridLayout(v2GroupBox);
 
199
      v2GroupBoxLayout->setMargin(2);
 
200
      v2GroupBoxLayout->setSpacing(4);
 
201
      if (v2GroupBox) {
 
202
        m_totalNumTracksCheckBox = new QCheckBox(i18n("Use &track/total number of tracks format"), v2GroupBox);
 
203
        v2GroupBoxLayout->addWidget(m_totalNumTracksCheckBox, 0, 0, 1, 2);
 
204
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
205
        m_genreNotNumericCheckBox = new QCheckBox(i18n("&Genre as text instead of numeric string"), v2GroupBox);
 
206
        QLabel* textEncodingLabel = new QLabel(i18n("Text &encoding:"), v2GroupBox);
 
207
        m_textEncodingComboBox = new QComboBox(v2GroupBox);
 
208
#endif
 
209
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
 
210
        QLabel* id3v2VersionLabel = new QLabel(i18n("&Version used for new tags:"), v2GroupBox);
 
211
        m_id3v2VersionComboBox = new QComboBox(v2GroupBox);
 
212
#endif
 
213
        QLabel* trackNumberDigitsLabel = new QLabel(i18n("Track number &digits:"), v2GroupBox);
 
214
        m_trackNumberDigitsSpinBox = new QSpinBox(v2GroupBox);
 
215
        m_trackNumberDigitsSpinBox->setMaximum(5);
 
216
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
217
        if (textEncodingLabel && m_textEncodingComboBox) {
 
218
          m_textEncodingComboBox->insertItem(MiscConfig::TE_ISO8859_1, i18n("ISO-8859-1"));
 
219
          m_textEncodingComboBox->insertItem(MiscConfig::TE_UTF16, i18n("UTF16"));
 
220
          m_textEncodingComboBox->insertItem(MiscConfig::TE_UTF8, i18n("UTF8"));
 
221
          m_textEncodingComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
 
222
          textEncodingLabel->setBuddy(m_textEncodingComboBox);
 
223
          v2GroupBoxLayout->addWidget(m_genreNotNumericCheckBox, 1, 0, 1, 2);
 
224
          v2GroupBoxLayout->addWidget(textEncodingLabel, 2, 0);
 
225
          v2GroupBoxLayout->addWidget(m_textEncodingComboBox, 2, 1);
 
226
        }
 
227
#endif
 
228
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
 
229
        if (id3v2VersionLabel && m_id3v2VersionComboBox) {
 
230
          m_id3v2VersionComboBox->insertItem(MiscConfig::ID3v2_3_0, i18n("ID3v2.3.0 (id3lib)"));
 
231
          m_id3v2VersionComboBox->insertItem(MiscConfig::ID3v2_4_0, i18n("ID3v2.4.0 (TagLib)"));
 
232
          m_id3v2VersionComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
 
233
          id3v2VersionLabel->setBuddy(m_id3v2VersionComboBox);
 
234
          v2GroupBoxLayout->addWidget(id3v2VersionLabel, 3, 0);
 
235
          v2GroupBoxLayout->addWidget(m_id3v2VersionComboBox, 3, 1);
 
236
        }
 
237
#endif
 
238
        if (trackNumberDigitsLabel && m_trackNumberDigitsSpinBox) {
 
239
          trackNumberDigitsLabel->setBuddy(m_trackNumberDigitsSpinBox);
 
240
          v2GroupBoxLayout->addWidget(trackNumberDigitsLabel, 4, 0);
 
241
          v2GroupBoxLayout->addWidget(m_trackNumberDigitsSpinBox, 4, 1);
 
242
        }
 
243
        vlayout->addWidget(v2GroupBox);
 
244
      }
 
245
#ifdef HAVE_VORBIS
 
246
      QGroupBox* vorbisGroupBox = new QGroupBox(i18n("Ogg/Vorbis"), tagsPage);
 
247
      if (vorbisGroupBox) {
 
248
        QLabel* commentNameLabel = new QLabel(i18n("Comment field &name:"), vorbisGroupBox);
 
249
        m_commentNameComboBox = new QComboBox(vorbisGroupBox);
 
250
        QLabel* pictureNameLabel = new QLabel(i18n("&Picture field name:"), vorbisGroupBox);
 
251
        m_pictureNameComboBox = new QComboBox(vorbisGroupBox);
 
252
        if (commentNameLabel && m_commentNameComboBox &&
 
253
            pictureNameLabel && m_pictureNameComboBox) {
 
254
          m_commentNameComboBox->setEditable(true);
 
255
          QStringList items;
 
256
          items += "COMMENT";
 
257
          items += "DESCRIPTION";
 
258
          m_commentNameComboBox->addItems(items);
 
259
          m_commentNameComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
 
260
          commentNameLabel->setBuddy(m_commentNameComboBox);
 
261
          m_pictureNameComboBox->addItems(QStringList() << "METADATA_BLOCK_PICTURE" << "COVERART");
 
262
          m_pictureNameComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
 
263
          pictureNameLabel->setBuddy(m_pictureNameComboBox);
 
264
        }
 
265
        QGridLayout* vorbisGroupBoxLayout = new QGridLayout(vorbisGroupBox);
 
266
        vorbisGroupBoxLayout->setMargin(2);
 
267
        vorbisGroupBoxLayout->setSpacing(4);
 
268
        vorbisGroupBoxLayout->addWidget(commentNameLabel, 0, 0);
 
269
        vorbisGroupBoxLayout->addWidget(m_commentNameComboBox, 0, 1);
 
270
        vorbisGroupBoxLayout->addWidget(pictureNameLabel, 1, 0);
 
271
        vorbisGroupBoxLayout->addWidget(m_pictureNameComboBox, 1, 1);
 
272
        vorbisGroupBox->setLayout(vorbisGroupBoxLayout);
 
273
        vlayout->addWidget(vorbisGroupBox);
 
274
      }
 
275
#endif
 
276
      QHBoxLayout* hlayout = new QHBoxLayout;
 
277
      if (hlayout) {
 
278
        QGroupBox* genresGroupBox = new QGroupBox(i18n("Custom &Genres"), tagsPage);
 
279
        if (genresGroupBox) {
 
280
          m_onlyCustomGenresCheckBox = new QCheckBox(i18n("&Show only custom genres"), genresGroupBox);
 
281
          m_genresEditModel = new QStringListModel(genresGroupBox);
 
282
          StringListEdit* genresEdit = new StringListEdit(m_genresEditModel, genresGroupBox);
 
283
          QVBoxLayout* vbox = new QVBoxLayout;
 
284
          vbox->setMargin(2);
 
285
          vbox->addWidget(m_onlyCustomGenresCheckBox);
 
286
          vbox->addWidget(genresEdit);
 
287
          genresGroupBox->setLayout(vbox);
 
288
          hlayout->addWidget(genresGroupBox);
 
289
        }
 
290
        QString id3FormatTitle(i18n("&Tag Format"));
 
291
        m_id3FormatBox = new FormatBox(id3FormatTitle, tagsPage);
 
292
        if (m_id3FormatBox) {
 
293
          hlayout->addWidget(m_id3FormatBox);
 
294
        }
 
295
        vlayout->addLayout(hlayout);
 
296
      }
 
297
    }
 
298
#ifdef CONFIG_USE_KDE
 
299
    addPage(tagsPage, i18n("Tags"), "applications-multimedia");
 
300
#else
 
301
    tabWidget->addTab(tagsPage, i18n("&Tags"));
 
302
#endif
 
303
  }
 
304
 
 
305
  QWidget* filesPage = new QWidget;
 
306
  if (filesPage) {
 
307
    QVBoxLayout* vlayout = new QVBoxLayout(filesPage);
 
308
    if (vlayout) {
 
309
      vlayout->setMargin(6);
 
310
      vlayout->setSpacing(6);
 
311
      QGroupBox* saveGroupBox = new QGroupBox(i18n("Save"), filesPage);
 
312
      if (saveGroupBox) {
 
313
        m_preserveTimeCheckBox = new QCheckBox(i18n("&Preserve file timestamp"), saveGroupBox);
 
314
        m_markChangesCheckBox = new QCheckBox(i18n("&Mark changes"), saveGroupBox);
 
315
        QVBoxLayout* vbox = new QVBoxLayout;
 
316
        vbox->setMargin(2);
 
317
        vbox->addWidget(m_preserveTimeCheckBox);
 
318
        vbox->addWidget(m_markChangesCheckBox);
 
319
        saveGroupBox->setLayout(vbox);
 
320
        vlayout->addWidget(saveGroupBox);
 
321
      }
 
322
      QString fnFormatTitle(i18n("&Filename Format"));
 
323
      m_fnFormatBox = new FormatBox(fnFormatTitle, filesPage);
 
324
      if (m_fnFormatBox) {
 
325
        vlayout->addWidget(m_fnFormatBox);
 
326
      }
 
327
    }
 
328
#ifdef CONFIG_USE_KDE
 
329
    addPage(filesPage, i18n("Files"), "document-save");
 
330
#else
 
331
    tabWidget->addTab(filesPage, i18n("&Files"));
 
332
#endif
 
333
  }
 
334
 
 
335
  QWidget* actionsPage = new QWidget;
 
336
  if (actionsPage) {
 
337
    QVBoxLayout* vlayout = new QVBoxLayout(actionsPage);
 
338
    if (vlayout) {
 
339
      vlayout->setMargin(6);
 
340
      vlayout->setSpacing(6);
 
341
      QGroupBox* browserGroupBox = new QGroupBox(i18n("Browser"), actionsPage);
 
342
      if (browserGroupBox) {
 
343
        QLabel* browserLabel = new QLabel(i18n("Web &browser:"), browserGroupBox);
 
344
        m_browserLineEdit = new QLineEdit(browserGroupBox);
 
345
        if (browserLabel && m_browserLineEdit) {
 
346
          browserLabel->setBuddy(m_browserLineEdit);
 
347
        }
 
348
        QHBoxLayout* hbox = new QHBoxLayout;
 
349
        hbox->setMargin(2);
 
350
        hbox->addWidget(browserLabel);
 
351
        hbox->addWidget(m_browserLineEdit);
 
352
        browserGroupBox->setLayout(hbox);
 
353
        vlayout->addWidget(browserGroupBox);
 
354
      }
 
355
 
 
356
      QGroupBox* commandsGroupBox = new QGroupBox(i18n("Context &Menu Commands"), actionsPage);
 
357
      if (commandsGroupBox) {
 
358
        m_playOnDoubleClickCheckBox =
 
359
            new QCheckBox(i18n("&Play on double click"), commandsGroupBox);
 
360
        m_commandsTableModel = new CommandsTableModel(commandsGroupBox);
 
361
        m_commandsTable = new ConfigTable(commandsGroupBox);
 
362
        m_commandsTable->setModel(m_commandsTableModel);
 
363
        m_commandsTable->setHorizontalResizeModes(
 
364
          m_commandsTableModel->getHorizontalResizeModes());
 
365
        QVBoxLayout* commandsLayout = new QVBoxLayout;
 
366
        commandsLayout->setMargin(2);
 
367
        commandsLayout->addWidget(m_playOnDoubleClickCheckBox);
 
368
        commandsLayout->addWidget(m_commandsTable);
 
369
        commandsGroupBox->setLayout(commandsLayout);
 
370
        vlayout->addWidget(commandsGroupBox);
 
371
      }
 
372
    }
 
373
#ifdef CONFIG_USE_KDE
 
374
    addPage(actionsPage, i18n("User Actions"), "preferences-other");
 
375
#else
 
376
    tabWidget->addTab(actionsPage, i18n("&User Actions"));
 
377
#endif
 
378
  }
 
379
 
 
380
  QWidget* networkPage = new QWidget;
 
381
  if (networkPage) {
 
382
    QVBoxLayout* vlayout = new QVBoxLayout(networkPage);
 
383
    if (vlayout) {
 
384
      vlayout->setMargin(6);
 
385
      vlayout->setSpacing(6);
 
386
      QGroupBox* proxyGroupBox = new QGroupBox(i18n("Proxy"), networkPage);
 
387
      if (proxyGroupBox) {
 
388
        m_proxyCheckBox = new QCheckBox(i18n("&Proxy:"), proxyGroupBox);
 
389
        m_proxyLineEdit = new QLineEdit(proxyGroupBox);
 
390
        m_proxyAuthenticationCheckBox = new QCheckBox(i18n("&Use authentication with proxy"), proxyGroupBox);
 
391
        QLabel* proxyUserNameLabel = new QLabel(i18n("Proxy user &name:"), proxyGroupBox);
 
392
        m_proxyUserNameLineEdit = new QLineEdit(proxyGroupBox);
 
393
        proxyUserNameLabel->setBuddy(m_proxyUserNameLineEdit);
 
394
        QLabel* proxyPasswordLabel = new QLabel(i18n("Proxy pass&word:"), proxyGroupBox);
 
395
        m_proxyPasswordLineEdit = new QLineEdit(proxyGroupBox);
 
396
        proxyPasswordLabel->setBuddy(m_proxyPasswordLineEdit);
 
397
        m_proxyPasswordLineEdit->setEchoMode(QLineEdit::Password);
 
398
        QVBoxLayout* vbox = new QVBoxLayout;
 
399
        vbox->setMargin(2);
 
400
        QHBoxLayout* proxyHbox = new QHBoxLayout;
 
401
        proxyHbox->setMargin(2);
 
402
        proxyHbox->addWidget(m_proxyCheckBox);
 
403
        proxyHbox->addWidget(m_proxyLineEdit);
 
404
        vbox->addLayout(proxyHbox);
 
405
        vbox->addWidget(m_proxyAuthenticationCheckBox);
 
406
        QGridLayout* authLayout = new QGridLayout;
 
407
        authLayout->addWidget(proxyUserNameLabel, 0, 0);
 
408
        authLayout->addWidget(m_proxyUserNameLineEdit, 0, 1);
 
409
        authLayout->addWidget(proxyPasswordLabel, 1, 0);
 
410
        authLayout->addWidget(m_proxyPasswordLineEdit, 1, 1);
 
411
        vbox->addLayout(authLayout);
 
412
        proxyGroupBox->setLayout(vbox);
 
413
        vlayout->addWidget(proxyGroupBox);
 
414
      }
 
415
 
 
416
      QSpacerItem* vspacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
 
417
      vlayout->addItem(vspacer);
 
418
    }
 
419
#ifdef CONFIG_USE_KDE
 
420
    addPage(networkPage, i18n("Network"), "preferences-system-network");
 
421
#else
 
422
    tabWidget->addTab(networkPage, i18n("&Network"));
 
423
#endif
 
424
  }
 
425
 
 
426
#ifndef CONFIG_USE_KDE
 
427
  QWidget* appearancePage = new QWidget;
 
428
  if (appearancePage) {
 
429
    QVBoxLayout* vlayout = new QVBoxLayout(appearancePage);
 
430
    if (vlayout) {
 
431
      vlayout->setMargin(6);
 
432
      vlayout->setSpacing(6);
 
433
      QGridLayout* fontStyleLayout = new QGridLayout;
 
434
 
 
435
      m_useApplicationFontCheckBox = new QCheckBox(i18n("Use custom app&lication font"), appearancePage);
 
436
      m_applicationFontButton = new QPushButton(i18n("A&pplication Font..."), appearancePage);
 
437
      m_useApplicationStyleCheckBox = new QCheckBox(i18n("Use custom application &style"), appearancePage);
 
438
      m_applicationStyleComboBox = new QComboBox(appearancePage);
 
439
      if (fontStyleLayout &&
 
440
          m_useApplicationFontCheckBox && m_applicationFontButton &&
 
441
          m_useApplicationStyleCheckBox && m_applicationStyleComboBox) {
 
442
        fontStyleLayout->setMargin(2);
 
443
        fontStyleLayout->setSpacing(4);
 
444
        fontStyleLayout->addWidget(m_useApplicationFontCheckBox, 0, 0);
 
445
        fontStyleLayout->addWidget(m_applicationFontButton, 0, 1);
 
446
        fontStyleLayout->addWidget(m_useApplicationStyleCheckBox, 1, 0);
 
447
        fontStyleLayout->addWidget(m_applicationStyleComboBox, 1, 1);
 
448
        m_applicationStyleComboBox->addItem(i18n("Unknown"));
 
449
        m_applicationStyleComboBox->addItems(QStyleFactory::keys());
 
450
        connect(m_applicationFontButton, SIGNAL(clicked()), this, SLOT(slotSelectFont()));
 
451
        connect(m_applicationStyleComboBox, SIGNAL(activated(const QString&)), this, SLOT(slotSelectStyle(const QString&)));
 
452
        connect(m_useApplicationFontCheckBox, SIGNAL(toggled(bool)), m_applicationFontButton, SLOT(setEnabled(bool)));
 
453
        connect(m_useApplicationStyleCheckBox, SIGNAL(toggled(bool)), m_applicationStyleComboBox, SLOT(setEnabled(bool)));
 
454
        vlayout->addLayout(fontStyleLayout);
 
455
      }
 
456
      QSpacerItem* vspacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
 
457
      vlayout->addItem(vspacer);
 
458
    }
 
459
    tabWidget->addTab(appearancePage, i18n("&Appearance"));
 
460
  }
 
461
  m_fontChanged = false;
 
462
  m_styleChanged = false;
 
463
 
 
464
  topLayout->addWidget(tabWidget);
 
465
  QHBoxLayout* hlayout = new QHBoxLayout;
 
466
  QSpacerItem* hspacer = new QSpacerItem(16, 0, QSizePolicy::Expanding,
 
467
                                         QSizePolicy::Minimum);
 
468
  QPushButton* helpButton = new QPushButton(i18n("&Help"), this);
 
469
  QPushButton* okButton = new QPushButton(i18n("&OK"), this);
 
470
  QPushButton* cancelButton = new QPushButton(i18n("&Cancel"), this);
 
471
  if (hlayout && helpButton && okButton && cancelButton) {
 
472
    hlayout->addWidget(helpButton);
 
473
    hlayout->addItem(hspacer);
 
474
    hlayout->addWidget(okButton);
 
475
    hlayout->addWidget(cancelButton);
 
476
    okButton->setDefault(true);
 
477
    connect(helpButton, SIGNAL(clicked()), this, SLOT(slotHelp()));
 
478
    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
 
479
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 
480
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotRevertFontAndStyle()));
 
481
    topLayout->addLayout(hlayout);
 
482
  }
 
483
#else
 
484
  setButtons(Ok | Cancel | Help);
 
485
  setHelp("configure-kid3");
 
486
#endif
 
487
}
 
488
 
 
489
/**
 
490
 * Destructor.
 
491
 */
 
492
ConfigDialog::~ConfigDialog()
 
493
{}
 
494
 
 
495
/**
 
496
 * Set values in dialog from current configuration.
 
497
 *
 
498
 * @param fnCfg   filename format configuration
 
499
 * @param fnCfg   ID3 format configuration
 
500
 * @param miscCfg misc. configuration
 
501
 */
 
502
void ConfigDialog::setConfig(const FormatConfig* fnCfg,
 
503
               const FormatConfig* id3Cfg,
 
504
               const MiscConfig* miscCfg)
 
505
{
 
506
  m_fnFormatBox->fromFormatConfig(fnCfg);
 
507
  m_id3FormatBox->fromFormatConfig(id3Cfg);
 
508
  m_markTruncationsCheckBox->setChecked(miscCfg->m_markTruncations);
 
509
  m_totalNumTracksCheckBox->setChecked(miscCfg->m_enableTotalNumberOfTracks);
 
510
  m_preserveTimeCheckBox->setChecked(miscCfg->m_preserveTime);
 
511
  m_markChangesCheckBox->setChecked(miscCfg->m_markChanges);
 
512
  m_onlyCustomGenresCheckBox->setChecked(miscCfg->m_onlyCustomGenres);
 
513
  m_genresEditModel->setStringList(miscCfg->m_customGenres);
 
514
  m_commandsTableModel->setCommandList(miscCfg->m_contextMenuCommands);
 
515
#ifdef HAVE_VORBIS
 
516
  int idx = m_commentNameComboBox->findText(miscCfg->m_commentName);
 
517
  if (idx >= 0) {
 
518
    m_commentNameComboBox->setCurrentIndex(idx);
 
519
  } else {
 
520
    m_commentNameComboBox->addItem(miscCfg->m_commentName);
 
521
    m_commentNameComboBox->setCurrentIndex(m_commentNameComboBox->count() - 1);
 
522
  }
 
523
  m_pictureNameComboBox->setCurrentIndex(miscCfg->m_pictureNameItem);
 
524
#endif
 
525
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
526
  m_genreNotNumericCheckBox->setChecked(miscCfg->m_genreNotNumeric);
 
527
  int textEncodingV1Index = TextEncodingV1Latin1Index;
 
528
  int index = 0;
 
529
  for (QStringList::const_iterator it = m_textEncodingV1List.begin();
 
530
       it != m_textEncodingV1List.end();
 
531
       ++it) {
 
532
    if (getTextEncodingV1CodecName(*it) == miscCfg->m_textEncodingV1) {
 
533
      textEncodingV1Index = index;
 
534
      break;
 
535
    }
 
536
    ++index;
 
537
  }
 
538
  m_textEncodingV1ComboBox->setCurrentIndex(textEncodingV1Index);
 
539
  m_textEncodingComboBox->setCurrentIndex(miscCfg->m_textEncoding);
 
540
#endif
 
541
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
 
542
  m_id3v2VersionComboBox->setCurrentIndex(miscCfg->m_id3v2Version);
 
543
#endif
 
544
  m_trackNumberDigitsSpinBox->setValue(miscCfg->m_trackNumberDigits);
 
545
  m_browserLineEdit->setText(miscCfg->m_browser);
 
546
  m_playOnDoubleClickCheckBox->setChecked(miscCfg->m_playOnDoubleClick);
 
547
  m_proxyCheckBox->setChecked(miscCfg->m_useProxy);
 
548
  m_proxyLineEdit->setText(miscCfg->m_proxy);
 
549
  m_proxyAuthenticationCheckBox->setChecked(miscCfg->m_useProxyAuthentication);
 
550
  m_proxyUserNameLineEdit->setText(miscCfg->m_proxyUserName);
 
551
  m_proxyPasswordLineEdit->setText(miscCfg->m_proxyPassword);
 
552
#ifndef CONFIG_USE_KDE
 
553
  m_useApplicationFontCheckBox->setChecked(miscCfg->m_useFont);
 
554
  m_applicationFontButton->setEnabled(miscCfg->m_useFont);
 
555
  if (miscCfg->m_style.isEmpty()) {
 
556
    m_useApplicationStyleCheckBox->setChecked(false);
 
557
    m_applicationStyleComboBox->setEnabled(false);
 
558
    m_applicationStyleComboBox->setCurrentIndex(0);
 
559
  } else {
 
560
    m_useApplicationStyleCheckBox->setChecked(true);
 
561
    m_applicationStyleComboBox->setEnabled(true);
 
562
    int idx = m_applicationStyleComboBox->findText(miscCfg->m_style);
 
563
    if (idx >= 0) {
 
564
      m_applicationStyleComboBox->setCurrentIndex(idx);
 
565
    }
 
566
  }
 
567
 
 
568
  // store current font and style
 
569
  m_font = QApplication::font();
 
570
  m_style = miscCfg->m_style;
 
571
  m_fontChanged = false;
 
572
  m_styleChanged = false;
 
573
#endif
 
574
}
 
575
 
 
576
/**
 
577
 * Get values from dialog and store them in the current configuration.
 
578
 *
 
579
 * @param fnCfg   filename format configuration
 
580
 * @param fnCfg   ID3 format configuration
 
581
 * @param miscCfg misc. configuration
 
582
 */
 
583
void ConfigDialog::getConfig(FormatConfig* fnCfg,
 
584
               FormatConfig* id3Cfg,
 
585
               MiscConfig* miscCfg) const
 
586
{
 
587
  m_fnFormatBox->toFormatConfig(fnCfg);
 
588
  m_id3FormatBox->toFormatConfig(id3Cfg);
 
589
  miscCfg->m_markTruncations = m_markTruncationsCheckBox->isChecked();
 
590
  miscCfg->m_enableTotalNumberOfTracks = m_totalNumTracksCheckBox->isChecked();
 
591
  miscCfg->m_preserveTime = m_preserveTimeCheckBox->isChecked();
 
592
  miscCfg->m_markChanges = m_markChangesCheckBox->isChecked();
 
593
  miscCfg->m_onlyCustomGenres = m_onlyCustomGenresCheckBox->isChecked();
 
594
  miscCfg->m_customGenres = m_genresEditModel->stringList();
 
595
  miscCfg->m_contextMenuCommands = m_commandsTableModel->getCommandList();
 
596
#ifdef HAVE_VORBIS
 
597
  miscCfg->m_commentName = m_commentNameComboBox->currentText();
 
598
  miscCfg->m_pictureNameItem = m_pictureNameComboBox->currentIndex();
 
599
#endif
 
600
#if defined HAVE_ID3LIB || defined HAVE_TAGLIB
 
601
  miscCfg->m_genreNotNumeric = m_genreNotNumericCheckBox->isChecked();
 
602
  miscCfg->m_textEncodingV1 =
 
603
    getTextEncodingV1CodecName(m_textEncodingV1ComboBox->currentText());
 
604
  miscCfg->m_textEncoding = m_textEncodingComboBox->currentIndex();
 
605
#endif
 
606
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
 
607
  miscCfg->m_id3v2Version = m_id3v2VersionComboBox->currentIndex();
 
608
#endif
 
609
  miscCfg->m_trackNumberDigits = m_trackNumberDigitsSpinBox->value();
 
610
  miscCfg->m_browser = m_browserLineEdit->text();
 
611
  miscCfg->m_playOnDoubleClick = m_playOnDoubleClickCheckBox->isChecked();
 
612
  miscCfg->m_useProxy = m_proxyCheckBox->isChecked();
 
613
  miscCfg->m_proxy = m_proxyLineEdit->text();
 
614
  miscCfg->m_useProxyAuthentication = m_proxyAuthenticationCheckBox->isChecked();
 
615
  miscCfg->m_proxyUserName = m_proxyUserNameLineEdit->text();
 
616
  miscCfg->m_proxyPassword = m_proxyPasswordLineEdit->text();
 
617
#ifndef CONFIG_USE_KDE
 
618
  if (m_useApplicationFontCheckBox->isChecked()) {
 
619
    QFont font = QApplication::font();
 
620
    miscCfg->m_fontFamily = font.family();
 
621
    miscCfg->m_fontSize = font.pointSize();
 
622
    miscCfg->m_useFont = true;
 
623
  } else {
 
624
    miscCfg->m_useFont = false;
 
625
  }
 
626
  if (!m_useApplicationStyleCheckBox->isChecked() ||
 
627
      m_applicationStyleComboBox->currentIndex() == 0) {
 
628
    miscCfg->m_style = "";
 
629
  } else {
 
630
    miscCfg->m_style = m_applicationStyleComboBox->currentText();
 
631
  }
 
632
#endif
 
633
}
 
634
 
 
635
/**
 
636
 * Show help.
 
637
 */
 
638
void ConfigDialog::slotHelp()
 
639
{
 
640
  ContextHelp::displayHelp("configure-kid3");
 
641
}
 
642
 
 
643
#ifndef CONFIG_USE_KDE
 
644
/**
 
645
 * Select custom application font.
 
646
 */
 
647
void ConfigDialog::slotSelectFont()
 
648
{
 
649
  bool ok;
 
650
  QFont font = QFontDialog::getFont(&ok, QApplication::font(), this);
 
651
  if (ok) {
 
652
    font.setWeight(QFont::Normal);
 
653
    font.setItalic(false);
 
654
    font.setBold(false);
 
655
    font.setUnderline(false);
 
656
    font.setOverline(false);
 
657
    font.setStrikeOut(false);
 
658
    QApplication::setFont(font);
 
659
    m_fontChanged = true;
 
660
  }
 
661
}
 
662
 
 
663
/**
 
664
 * Select custom application style.
 
665
 *
 
666
 * @param key style key
 
667
 */
 
668
void ConfigDialog::slotSelectStyle(const QString& key)
 
669
{
 
670
  if (key != i18n("Unknown") &&
 
671
      QApplication::setStyle(key)) {
 
672
    m_styleChanged = true;
 
673
  }
 
674
}
 
675
 
 
676
/**
 
677
 * Revert the font and style to the values in the settings.
 
678
 */
 
679
void ConfigDialog::slotRevertFontAndStyle()
 
680
{
 
681
  if (m_fontChanged) {
 
682
    QApplication::setFont(m_font);
 
683
    m_fontChanged = false;
 
684
  }
 
685
  if (m_styleChanged && !m_style.isEmpty()) {
 
686
    QApplication::setStyle(m_style);
 
687
    m_styleChanged = false;
 
688
  }
 
689
}
 
690
#endif