EditProfileDialog.cpp 48.2 KB
Newer Older
1
/*
2
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

20 21 22
// Own
#include "EditProfileDialog.h"

Jekyll Wu's avatar
Jekyll Wu committed
23 24 25
// Standard
#include <cmath>

26
// Qt
Dirk Mueller's avatar
Dirk Mueller committed
27 28
#include <QtGui/QBrush>
#include <QtGui/QPainter>
29
#include <QStandardItem>
30
#include <QtCore/QTextCodec>
31 32
#include <QtGui/QLinearGradient>
#include <QtGui/QRadialGradient>
33
#include <QtCore/QTimer>
34 35
#include <QtCore/QTimeLine>

36
// KDE
37 38 39 40
#include <kdeversion.h>
#if KDE_IS_VERSION(4, 9, 1)
#include <KCodecAction>
#else
41
#include <kcodecaction.h>
42 43
#endif

44 45
#include <KFontDialog>
#include <KIcon>
46
#include <KIconDialog>
47
#include <KFileDialog>
48
#include <KUrlCompletion>
49
#include <KWindowSystem>
Rick Xing's avatar
Rick Xing committed
50
#include <KTextEdit>
51
#include <KMessageBox>
52 53 54

// Konsole
#include "ColorScheme.h"
55
#include "ColorSchemeManager.h"
56
#include "ColorSchemeEditor.h"
57
#include "ui_EditProfileDialog.h"
58 59
#include "KeyBindingEditor.h"
#include "KeyboardTranslator.h"
60
#include "KeyboardTranslatorManager.h"
61
#include "ProfileManager.h"
62
#include "ShellCommand.h"
63
#include "WindowSystemInfo.h"
64
#include "Enumeration.h"
65

66 67
using namespace Konsole;

68 69
EditProfileDialog::EditProfileDialog(QWidget* aParent)
    : KDialog(aParent)
Robert Knight's avatar
 
Robert Knight committed
70
    , _colorSchemeAnimationTimeLine(0)
71
    , _delayedPreviewTimer(new QTimer(this))
72
{
73
    setCaption(i18n("Edit Profile"));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
74
    setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
75

76 77 78
    // disable the apply button , since no modification has been made
    enableButtonApply(false);

79
    connect(this, SIGNAL(applyClicked()), this, SLOT(save()));
Jekyll Wu's avatar
Jekyll Wu committed
80

81
    connect(_delayedPreviewTimer, SIGNAL(timeout()), this, SLOT(delayedPreviewActivate()));
Jekyll Wu's avatar
Jekyll Wu committed
82

83
    _ui = new Ui::EditProfileDialog();
84
    _ui->setupUi(mainWidget());
85

86 87 88 89 90 91 92 93 94 95
    // there are various setupXYZPage() methods to load the items
    // for each page and update their states to match the profile
    // being edited.
    //
    // these are only called when needed ( ie. when the user clicks
    // the tab to move to that page ).
    //
    // the _pageNeedsUpdate vector keeps track of the pages that have
    // not been updated since the last profile change and will need
    // to be refreshed when the user switches to them
Kurt Hindenburg's avatar
Kurt Hindenburg committed
96
    _pageNeedsUpdate.resize(_ui->tabWidget->count());
97
    connect(_ui->tabWidget, SIGNAL(currentChanged(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
98
            SLOT(preparePage(int)));
99

100
    createTempProfile();
101
}
102
EditProfileDialog::~EditProfileDialog()
103 104
{
    delete _ui;
105
}
106
void EditProfileDialog::save()
107
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
108
    if (_tempProfile->isEmpty())
109
        return;
110

111
    ProfileManager::instance()->changeProfile(_profile, _tempProfile->setProperties());
112 113 114

    // ensure that these settings are not undone by a call
    // to unpreview()
Kurt Hindenburg's avatar
Kurt Hindenburg committed
115 116
    QHashIterator<Profile::Property, QVariant> iter(_tempProfile->setProperties());
    while (iter.hasNext()) {
117 118 119
        iter.next();
        _previewedProperties.remove(iter.key());
    }
120

121 122
    createTempProfile();

123
    enableButtonApply(false);
124 125 126 127 128
}
void EditProfileDialog::reject()
{
    unpreviewAll();
    KDialog::reject();
129 130 131
}
void EditProfileDialog::accept()
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
132 133
    Q_ASSERT(_profile);
    Q_ASSERT(_tempProfile);
134

Kurt Hindenburg's avatar
Kurt Hindenburg committed
135 136 137
    if ((_tempProfile->isPropertySet(Profile::Name) &&
            _tempProfile->name().isEmpty())
            || (_profile->name().isEmpty() && _tempProfile->name().isEmpty())) {
138
        KMessageBox::sorry(this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
139 140
                           i18n("<p>Each profile must have a name before it can be saved "
                                "into disk.</p>"));
141 142
        return;
    }
143
    save();
144
    unpreviewAll();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
145
    KDialog::accept();
146
}
147
QString EditProfileDialog::groupProfileNames(const ProfileGroup::Ptr group, int maxLength)
Robert Knight's avatar
 
Robert Knight committed
148
{
149 150
    QString caption;
    int count = group->profiles().count();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
151
    for (int i = 0; i < count; i++) {
152
        caption += group->profiles()[i]->name();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
153
        if (i < (count - 1)) {
154 155
            caption += ',';
            // limit caption length to prevent very long window titles
Kurt Hindenburg's avatar
Kurt Hindenburg committed
156
            if (maxLength > 0 && caption.length() > maxLength) {
157 158 159 160 161 162 163 164 165 166
                caption += "...";
                break;
            }
        }
    }
    return caption;
}
void EditProfileDialog::updateCaption(const Profile::Ptr profile)
{
    const int MAX_GROUP_CAPTION_LENGTH = 25;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
167 168 169 170 171 172 173 174 175
    ProfileGroup::Ptr group = profile->asGroup();
    if (group && group->profiles().count() > 1) {
        QString caption = groupProfileNames(group, MAX_GROUP_CAPTION_LENGTH);
        setCaption(i18np("Editing profile: %2",
                         "Editing %1 profiles: %2",
                         group->profiles().count(),
                         caption));
    } else {
        setCaption(i18n("Edit Profile \"%1\"", profile->name()));
176
    }
Robert Knight's avatar
 
Robert Knight committed
177
}
178
void EditProfileDialog::setProfile(Profile::Ptr profile)
179
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
180
    Q_ASSERT(profile);
181

182 183
    _profile = profile;

184
    // update caption
185
    updateCaption(profile);
186

187 188 189 190 191
    // mark each page of the dialog as out of date
    // and force an update of the currently visible page
    //
    // the other pages will be updated as necessary
    _pageNeedsUpdate.fill(true);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
192
    preparePage(_ui->tabWidget->currentIndex());
193

Kurt Hindenburg's avatar
Kurt Hindenburg committed
194
    if (_tempProfile) {
195
        createTempProfile();
196
    }
197
}
198
const Profile::Ptr EditProfileDialog::lookupProfile() const
199
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
200
    return _profile;
201
}
Robert Knight's avatar
 
Robert Knight committed
202
void EditProfileDialog::preparePage(int page)
203
{
Jekyll Wu's avatar
Jekyll Wu committed
204
    const Profile::Ptr profile = lookupProfile();
205

Kurt Hindenburg's avatar
Kurt Hindenburg committed
206
    Q_ASSERT(_pageNeedsUpdate.count() > page);
Jekyll Wu's avatar
Jekyll Wu committed
207
    Q_ASSERT(profile);
208

Robert Knight's avatar
 
Robert Knight committed
209
    QWidget* pageWidget = _ui->tabWidget->widget(page);
210

Kurt Hindenburg's avatar
Kurt Hindenburg committed
211 212
    if (_pageNeedsUpdate[page]) {
        if (pageWidget == _ui->generalTab)
Jekyll Wu's avatar
Jekyll Wu committed
213
            setupGeneralPage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
214
        else if (pageWidget == _ui->tabsTab)
Jekyll Wu's avatar
Jekyll Wu committed
215
            setupTabsPage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
216
        else if (pageWidget == _ui->appearanceTab)
Jekyll Wu's avatar
Jekyll Wu committed
217
            setupAppearancePage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
218
        else if (pageWidget == _ui->scrollingTab)
Jekyll Wu's avatar
Jekyll Wu committed
219
            setupScrollingPage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
220
        else if (pageWidget == _ui->keyboardTab)
Jekyll Wu's avatar
Jekyll Wu committed
221
            setupKeyboardPage(profile);
222 223
        else if (pageWidget == _ui->mouseTab)
            setupMousePage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
224
        else if (pageWidget == _ui->advancedTab)
Jekyll Wu's avatar
Jekyll Wu committed
225
            setupAdvancedPage(profile);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
226 227
        else
            Q_ASSERT(false);
228

229
        _pageNeedsUpdate[page] = false;
230
    }
Robert Knight's avatar
 
Robert Knight committed
231 232

    // start page entry animation for color schemes
Kurt Hindenburg's avatar
Kurt Hindenburg committed
233 234
    if (pageWidget == _ui->appearanceTab)
        _colorSchemeAnimationTimeLine->start();
Robert Knight's avatar
 
Robert Knight committed
235 236 237 238
}
void EditProfileDialog::selectProfileName()
{
    _ui->profileNameEdit->setFocus();
239
    _ui->profileNameEdit->selectAll();
240
}
Jekyll Wu's avatar
Jekyll Wu committed
241
void EditProfileDialog::setupGeneralPage(const Profile::Ptr profile)
242
{
243
    // basic profile options
244
    {
245 246 247 248
        _ui->emptyNameWarningWidget->setWordWrap(false);
        _ui->emptyNameWarningWidget->setCloseButtonVisible(false);
        _ui->emptyNameWarningWidget->setMessageType(KMessageWidget::Warning);

Jekyll Wu's avatar
Jekyll Wu committed
249
        ProfileGroup::Ptr group = profile->asGroup();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
250
        if (!group || group->profiles().count() < 2) {
Jekyll Wu's avatar
Jekyll Wu committed
251
            _ui->profileNameEdit->setText(profile->name());
252
            _ui->profileNameEdit->setClearButtonShown(true);
253

Jekyll Wu's avatar
Jekyll Wu committed
254
            _ui->emptyNameWarningWidget->setVisible(profile->name().isEmpty());
255
            _ui->emptyNameWarningWidget->setText(i18n("Profile name is empty."));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
256 257
        } else {
            _ui->profileNameEdit->setText(groupProfileNames(group, -1));
258
            _ui->profileNameEdit->setEnabled(false);
259
            _ui->profileNameLabel->setEnabled(false);
260 261

            _ui->emptyNameWarningWidget->setVisible(false);
262 263
        }
    }
264

Jekyll Wu's avatar
Jekyll Wu committed
265
    ShellCommand command(profile->command() , profile->arguments());
Kurt Hindenburg's avatar
Kurt Hindenburg committed
266
    _ui->commandEdit->setText(command.fullCommand());
267
    KUrlCompletion* exeCompletion = new KUrlCompletion(KUrlCompletion::ExeCompletion);
268
    exeCompletion->setParent(this);
269
    exeCompletion->setDir(QString());
Kurt Hindenburg's avatar
Kurt Hindenburg committed
270
    _ui->commandEdit->setCompletionObject(exeCompletion);
271

Jekyll Wu's avatar
Jekyll Wu committed
272
    _ui->initialDirEdit->setText(profile->defaultWorkingDirectory());
273 274
    KUrlCompletion* dirCompletion = new KUrlCompletion(KUrlCompletion::DirCompletion);
    dirCompletion->setParent(this);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
275
    _ui->initialDirEdit->setCompletionObject(dirCompletion);
276
    _ui->initialDirEdit->setClearButtonShown(true);
277

Kurt Hindenburg's avatar
Kurt Hindenburg committed
278
    _ui->dirSelectButton->setIcon(KIcon("folder-open"));
Jekyll Wu's avatar
Jekyll Wu committed
279
    _ui->iconSelectButton->setIcon(KIcon(profile->icon()));
280
    _ui->startInSameDirButton->setChecked(profile->startInCurrentSessionDir());
281

282
    // window options
283 284
    _ui->showTerminalSizeHintButton->setChecked(profile->showTerminalSizeHint());
    _ui->saveGeometryOnExitButton->setChecked(profile->saveGeometryOnExit());
285 286

    // signals and slots
287 288 289
    connect(_ui->dirSelectButton, SIGNAL(clicked()), this, SLOT(selectInitialDir()));
    connect(_ui->iconSelectButton, SIGNAL(clicked()), this, SLOT(selectIcon()));
    connect(_ui->startInSameDirButton, SIGNAL(toggled(bool)), this ,
290
            SLOT(startInSameDir(bool)));
291
    connect(_ui->profileNameEdit, SIGNAL(textChanged(QString)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
292
            SLOT(profileNameChanged(QString)));
293
    connect(_ui->initialDirEdit, SIGNAL(textChanged(QString)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
294
            SLOT(initialDirChanged(QString)));
295
    connect(_ui->commandEdit, SIGNAL(textChanged(QString)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
296
            SLOT(commandChanged(QString)));
297
    connect(_ui->environmentEditButton , SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
298
            SLOT(showEnvironmentEditor()));
Jekyll Wu's avatar
Jekyll Wu committed
299

300
    connect(_ui->saveGeometryOnExitButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
301
            SLOT(saveGeometryOnExit(bool)));
302
    connect(_ui->showTerminalSizeHintButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
303
            SLOT(showTerminalSizeHint(bool)));
304 305 306
}
void EditProfileDialog::showEnvironmentEditor()
{
Jekyll Wu's avatar
Jekyll Wu committed
307
    const Profile::Ptr profile = lookupProfile();
308

Kurt Hindenburg's avatar
Kurt Hindenburg committed
309 310
    QWeakPointer<KDialog> dialog = new KDialog(this);
    KTextEdit* edit = new KTextEdit(dialog.data());
311

312
    QStringList currentEnvironment = profile->environment();
313

Kurt Hindenburg's avatar
Kurt Hindenburg committed
314
    edit->setPlainText(currentEnvironment.join("\n"));
315
    edit->setToolTip(i18nc("@info:tooltip", "One environment variable per line"));
316

Kurt Hindenburg's avatar
Kurt Hindenburg committed
317 318
    dialog.data()->setPlainCaption(i18n("Edit Environment"));
    dialog.data()->setMainWidget(edit);
319

Kurt Hindenburg's avatar
Kurt Hindenburg committed
320
    if (dialog.data()->exec() == QDialog::Accepted) {
321
        QStringList newEnvironment = edit->toPlainText().split('\n');
Kurt Hindenburg's avatar
Kurt Hindenburg committed
322
        updateTempProfileProperty(Profile::Environment, newEnvironment);
323 324
    }

Kurt Hindenburg's avatar
Kurt Hindenburg committed
325
    delete dialog.data();
326
}
Jekyll Wu's avatar
Jekyll Wu committed
327
void EditProfileDialog::setupTabsPage(const Profile::Ptr profile)
328
{
329
    // tab title format
330 331 332 333 334 335 336
    _ui->renameTabWidget->setTabTitleText(profile->localTabTitleFormat());
    _ui->renameTabWidget->setRemoteTabTitleText(profile->remoteTabTitleFormat());

    connect(_ui->renameTabWidget, SIGNAL(tabTitleFormatChanged(QString)), this,
            SLOT(tabTitleFormatChanged(QString)));
    connect(_ui->renameTabWidget, SIGNAL(remoteTabTitleFormatChanged(QString)), this,
            SLOT(remoteTabTitleFormatChanged(QString)));
337

Jekyll Wu's avatar
Jekyll Wu committed
338
    // tab monitoring
Jekyll Wu's avatar
Jekyll Wu committed
339
    const int silenceSeconds = profile->silenceSeconds();
Jekyll Wu's avatar
Jekyll Wu committed
340
    _ui->silenceSecondsSpinner->setValue(silenceSeconds);
341
    _ui->silenceSecondsSpinner->setSuffix(ki18ncp("Unit of time", " second", " seconds"));
Jekyll Wu's avatar
Jekyll Wu committed
342

343 344
    connect(_ui->silenceSecondsSpinner, SIGNAL(valueChanged(int)),
            this, SLOT(silenceSecondsChanged(int)));
345
}
346

347
void EditProfileDialog::saveGeometryOnExit(bool value)
348
{
349
    updateTempProfileProperty(Profile::SaveGeometryOnExit, value);
350
}
351
void EditProfileDialog::showTerminalSizeHint(bool value)
352
{
353
    updateTempProfileProperty(Profile::ShowTerminalSizeHint, value);
354
}
355 356
void EditProfileDialog::tabTitleFormatChanged(const QString& format)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
357
    updateTempProfileProperty(Profile::LocalTabTitleFormat, format);
358 359 360
}
void EditProfileDialog::remoteTabTitleFormatChanged(const QString& format)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
361
    updateTempProfileProperty(Profile::RemoteTabTitleFormat, format);
362 363
}

364 365 366 367 368
void EditProfileDialog::silenceSecondsChanged(int seconds)
{
    updateTempProfileProperty(Profile::SilenceSeconds, seconds);
}

369 370
void EditProfileDialog::selectIcon()
{
Craig Drummond's avatar
Craig Drummond committed
371
    const QString& icon = KIconDialog::getIcon(KIconLoader::Desktop, KIconLoader::Application,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
372 373 374 375
                          false, 0, false, this);
    if (!icon.isEmpty()) {
        _ui->iconSelectButton->setIcon(KIcon(icon));
        updateTempProfileProperty(Profile::Icon, icon);
376 377 378 379
    }
}
void EditProfileDialog::profileNameChanged(const QString& text)
{
380 381
    _ui->emptyNameWarningWidget->setVisible(text.isEmpty());

Kurt Hindenburg's avatar
Kurt Hindenburg committed
382
    updateTempProfileProperty(Profile::Name, text);
383
    updateTempProfileProperty(Profile::UntranslatedName, text);
384
    updateCaption(_tempProfile);
385
}
386 387
void EditProfileDialog::startInSameDir(bool sameDir)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
388
    updateTempProfileProperty(Profile::StartInCurrentSessionDir, sameDir);
389
}
390 391
void EditProfileDialog::initialDirChanged(const QString& dir)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
392
    updateTempProfileProperty(Profile::Directory, dir);
393 394 395
}
void EditProfileDialog::commandChanged(const QString& command)
{
396 397
    ShellCommand shellCommand(command);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
398 399
    updateTempProfileProperty(Profile::Command, shellCommand.command());
    updateTempProfileProperty(Profile::Arguments, shellCommand.arguments());
400 401 402
}
void EditProfileDialog::selectInitialDir()
{
403
    const KUrl url = KFileDialog::getExistingDirectoryUrl(_ui->initialDirEdit->text(),
Kurt Hindenburg's avatar
Kurt Hindenburg committed
404 405
                     this,
                     i18n("Select Initial Directory"));
406

Kurt Hindenburg's avatar
Kurt Hindenburg committed
407
    if (!url.isEmpty())
408
        _ui->initialDirEdit->setText(url.path());
409
}
Jekyll Wu's avatar
Jekyll Wu committed
410
void EditProfileDialog::setupAppearancePage(const Profile::Ptr profile)
411
{
412
    ColorSchemeViewDelegate* delegate = new ColorSchemeViewDelegate(this);
413
    _ui->colorSchemeList->setItemDelegate(delegate);
414

Kurt Hindenburg's avatar
Kurt Hindenburg committed
415
    _colorSchemeAnimationTimeLine = new QTimeLine(500 , this);
Robert Knight's avatar
 
Robert Knight committed
416
    delegate->setEntryTimeLine(_colorSchemeAnimationTimeLine);
417

418
    connect(_colorSchemeAnimationTimeLine, SIGNAL(valueChanged(qreal)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
419
            SLOT(colorSchemeAnimationUpdate()));
420

Robert Knight's avatar
 
Robert Knight committed
421
    _ui->transparencyWarningWidget->setVisible(false);
422 423 424
    _ui->transparencyWarningWidget->setWordWrap(true);
    _ui->transparencyWarningWidget->setCloseButtonVisible(false);
    _ui->transparencyWarningWidget->setMessageType(KMessageWidget::Warning);
425

Robert Knight's avatar
 
Robert Knight committed
426 427 428
    _ui->editColorSchemeButton->setEnabled(false);
    _ui->removeColorSchemeButton->setEnabled(false);

429 430
    // setup color list
    updateColorSchemeList(true);
431

432 433
    _ui->colorSchemeList->setMouseTracking(true);
    _ui->colorSchemeList->installEventFilter(this);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
434
    _ui->colorSchemeList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
435

436
    connect(_ui->colorSchemeList->selectionModel(),
Kurt Hindenburg's avatar
Kurt Hindenburg committed
437
            SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
438 439
            this, SLOT(colorSchemeSelected()));
    connect(_ui->colorSchemeList, SIGNAL(entered(QModelIndex)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
440
            SLOT(previewColorScheme(QModelIndex)));
441

Robert Knight's avatar
 
Robert Knight committed
442
    updateColorSchemeButtons();
443

444
    connect(_ui->editColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
445
            SLOT(editColorScheme()));
446
    connect(_ui->removeColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
447
            SLOT(removeColorScheme()));
448
    connect(_ui->newColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
449
            SLOT(newColorScheme()));
450

451
    // setup font preview
Jekyll Wu's avatar
Jekyll Wu committed
452
    const bool antialias = profile->antiAliasFonts();
453

454 455
    QFont profileFont = profile->font();
    profileFont.setStyleStrategy(antialias ? QFont::PreferAntialias : QFont::NoAntialias);
456

457
    _ui->fontPreviewLabel->installEventFilter(this);
458
    _ui->fontPreviewLabel->setFont(profileFont);
459
    setFontInputValue(profileFont);
460

461 462
    connect(_ui->fontSizeInput, SIGNAL(valueChanged(double)), this,
            SLOT(setFontSize(double)));
463
    connect(_ui->selectFontButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
464
            SLOT(showFontDialog()));
465

Kurt Hindenburg's avatar
Kurt Hindenburg committed
466
    // setup font smoothing
467
    _ui->antialiasTextButton->setChecked(antialias);
468
    connect(_ui->antialiasTextButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
469
            SLOT(setAntialiasText(bool)));
470

Jekyll Wu's avatar
Jekyll Wu committed
471
    _ui->boldIntenseButton->setChecked(profile->boldIntense());
472
    connect(_ui->boldIntenseButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
473
            SLOT(setBoldIntense(bool)));
474 475 476
    _ui->enableMouseWheelZoomButton->setChecked(profile->mouseWheelZoomEnabled());
    connect(_ui->enableMouseWheelZoomButton, SIGNAL(toggled(bool)), this,
            SLOT(toggleMouseWheelZoom(bool)));
477 478 479
}
void EditProfileDialog::setAntialiasText(bool enable)
{
480 481
    QFont profileFont = _ui->fontPreviewLabel->font();
    profileFont.setStyleStrategy(enable ? QFont::PreferAntialias : QFont::NoAntialias);
482

483
    // update preview to reflect text smoothing state
484
    fontSelected(profileFont);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
485
    updateTempProfileProperty(Profile::AntiAliasFonts, enable);
486
}
487 488
void EditProfileDialog::setBoldIntense(bool enable)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
489 490
    preview(Profile::BoldIntense, enable);
    updateTempProfileProperty(Profile::BoldIntense, enable);
491
}
492 493 494 495
void EditProfileDialog::toggleMouseWheelZoom(bool enable)
{
    updateTempProfileProperty(Profile::MouseWheelZoomEnabled, enable);
}
496 497 498 499
void EditProfileDialog::colorSchemeAnimationUpdate()
{
    QAbstractItemModel* model = _ui->colorSchemeList->model();

Kurt Hindenburg's avatar
Kurt Hindenburg committed
500 501
    for (int i = model->rowCount() ; i >= 0 ; i--)
        _ui->colorSchemeList->update(model->index(i, 0));
502
}
503
void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
504
{
Robert Knight's avatar
 
Robert Knight committed
505 506
    if (!_ui->colorSchemeList->model())
        _ui->colorSchemeList->setModel(new QStandardItemModel(this));
507

508
    const QString& name = lookupProfile()->colorScheme();
509 510
    const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name);

Robert Knight's avatar
 
Robert Knight committed
511 512 513
    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->colorSchemeList->model());

    Q_ASSERT(model);
514

Robert Knight's avatar
 
Robert Knight committed
515 516
    model->clear();

517 518
    QStandardItem* selectedItem = 0;

519 520
    QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();

Kurt Hindenburg's avatar
Kurt Hindenburg committed
521
    foreach(const ColorScheme* scheme, schemeList) {
522 523
        QStandardItem* item = new QStandardItem(scheme->description());
        item->setData(QVariant::fromValue(scheme) ,  Qt::UserRole + 1);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
524
        item->setFlags(item->flags());
525

526
        if (currentScheme == scheme)
Kurt Hindenburg's avatar
Kurt Hindenburg committed
527
            selectedItem = item;
Robert Knight's avatar
 
Robert Knight committed
528

529 530 531
        model->appendRow(item);
    }

532 533
    model->sort(0);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
534
    if (selectCurrentScheme && selectedItem) {
535
        _ui->colorSchemeList->updateGeometry();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
536 537
        _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index() ,
                QItemSelectionModel::Select);
Robert Knight's avatar
 
Robert Knight committed
538 539 540

        // update transparency warning label
        updateTransparencyWarning();
541
    }
542
}
543
void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
544
{
Robert Knight's avatar
 
Robert Knight committed
545 546
    if (!_ui->keyBindingList->model())
        _ui->keyBindingList->setModel(new QStandardItemModel(this));
547

548
    const QString& name = lookupProfile()->keyBindings();
549

550
    KeyboardTranslatorManager* keyManager = KeyboardTranslatorManager::instance();
551
    const KeyboardTranslator* currentTranslator = keyManager->findTranslator(name);
552

Robert Knight's avatar
 
Robert Knight committed
553 554 555 556 557
    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->keyBindingList->model());

    Q_ASSERT(model);

    model->clear();
558

559 560
    QStandardItem* selectedItem = 0;

Jekyll Wu's avatar
Jekyll Wu committed
561
    QStringList translatorNames = keyManager->allTranslators();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
562
    foreach(const QString& translatorName, translatorNames) {
563
        const KeyboardTranslator* translator = keyManager->findTranslator(translatorName);
564 565

        QStandardItem* item = new QStandardItem(translator->description());
566
        item->setEditable(false);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
567 568
        item->setData(QVariant::fromValue(translator), Qt::UserRole + 1);
        item->setIcon(KIcon("preferences-desktop-keyboard"));
569

Kurt Hindenburg's avatar
Kurt Hindenburg committed
570
        if (translator == currentTranslator)
571
            selectedItem = item;
572 573 574 575

        model->appendRow(item);
    }

576
    model->sort(0);
577

Kurt Hindenburg's avatar
Kurt Hindenburg committed
578 579 580
    if (selectCurrentTranslator && selectedItem) {
        _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index() ,
                QItemSelectionModel::Select);
581
    }
582
}
583
bool EditProfileDialog::eventFilter(QObject* watched , QEvent* aEvent)
584
{
585
    if (watched == _ui->colorSchemeList && aEvent->type() == QEvent::Leave) {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
586 587
        if (_tempProfile->isPropertySet(Profile::ColorScheme))
            preview(Profile::ColorScheme, _tempProfile->colorScheme());
588 589
        else
            unpreview(Profile::ColorScheme);
590
    }
591
    if (watched == _ui->fontPreviewLabel && aEvent->type() == QEvent::FontChange) {
592
        const QFont& labelFont = _ui->fontPreviewLabel->font();
593
        _ui->fontPreviewLabel->setText(i18n("%1", labelFont.family()));
594
    }
595

596
    return KDialog::eventFilter(watched, aEvent);
597
}
598
void EditProfileDialog::unpreviewAll()
599
{
600 601 602
    _delayedPreviewTimer->stop();
    _delayedPreviewProperties.clear();

Kurt Hindenburg's avatar
Kurt Hindenburg committed
603 604 605
    QHash<Profile::Property, QVariant> map;
    QHashIterator<int, QVariant> iter(_previewedProperties);
    while (iter.hasNext()) {
606
        iter.next();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
607
        map.insert((Profile::Property)iter.key(), iter.value());
608 609 610
    }

    // undo any preview changes
Kurt Hindenburg's avatar
Kurt Hindenburg committed
611
    if (!map.isEmpty())
612
        ProfileManager::instance()->changeProfile(_profile, map, false);
613
}
614
void EditProfileDialog::unpreview(int aProperty)
615
{
616
    _delayedPreviewProperties.remove(aProperty);
617

618
    if (!_previewedProperties.contains(aProperty))
619
        return;
620

Kurt Hindenburg's avatar
Kurt Hindenburg committed
621
    QHash<Profile::Property, QVariant> map;
622
    map.insert((Profile::Property)aProperty, _previewedProperties[aProperty]);
623
    ProfileManager::instance()->changeProfile(_profile, map, false);
624

625
    _previewedProperties.remove(aProperty);
626
}
627
void EditProfileDialog::delayedPreview(int aProperty , const QVariant& value)
628
{
629
    _delayedPreviewProperties.insert(aProperty, value);
630 631

    _delayedPreviewTimer->stop();
632
    _delayedPreviewTimer->start(300);
633 634 635
}
void EditProfileDialog::delayedPreviewActivate()
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
636
    Q_ASSERT(qobject_cast<QTimer*>(sender()));
637

Kurt Hindenburg's avatar
Kurt Hindenburg committed
638 639
    QMutableHashIterator<int, QVariant> iter(_delayedPreviewProperties);
    if (iter.hasNext()) {
640
        iter.next();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
641
        preview(iter.key(), iter.value());
642 643
    }
}
644
void EditProfileDialog::preview(int aProperty , const QVariant& value)
645
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed