EditProfileDialog.cpp 49.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 29 30
#include <QtGui/QKeyEvent>
#include <QtGui/QBrush>
#include <QtGui/QPainter>
#include <QtGui/QStandardItem>
31
#include <QtCore/QTextCodec>
32 33
#include <QtGui/QLinearGradient>
#include <QtGui/QRadialGradient>
34
#include <QtCore/QTimer>
35 36
#include <QtCore/QTimeLine>

37
// KDE
38
#include <kcodecaction.h>
39 40
#include <KFontDialog>
#include <KIcon>
41
#include <KIconDialog>
42
#include <KFileDialog>
43
#include <KUrlCompletion>
44
#include <KWindowSystem>
Rick Xing's avatar
Rick Xing committed
45
#include <KTextEdit>
46
#include <KMessageBox>
47 48 49

// Konsole
#include "ColorScheme.h"
50
#include "ColorSchemeEditor.h"
51
#include "ui_EditProfileDialog.h"
52 53
#include "KeyBindingEditor.h"
#include "KeyboardTranslator.h"
54
#include "SessionManager.h"
55
#include "ShellCommand.h"
56
#include "TabTitleFormatAction.h"
57

58 59 60 61
// FIXME: it feels bad to include a big header file just
// in order to use one of its static members.
#include "TerminalDisplay.h"

62 63
using namespace Konsole;

64
EditProfileDialog::EditProfileDialog(QWidget* parent)
65
    : KDialog(parent)
Robert Knight's avatar
 
Robert Knight committed
66
    , _colorSchemeAnimationTimeLine(0)
67
    , _delayedPreviewTimer(new QTimer(this))
68
{
69
    setCaption(i18n("Edit Profile"));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
70
    setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
71

72 73 74
    // disable the apply button , since no modification has been made
    enableButtonApply(false);

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

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

79
    _ui = new Ui::EditProfileDialog();
80
    _ui->setupUi(mainWidget());
81

Jekyll Wu's avatar
Jekyll Wu committed
82
    // TODO: Re-enable in a later KDE 4.x release when this feature works again
83
    _ui->enableResizeWindowButton->setVisible(false);
Jekyll Wu's avatar
Jekyll Wu committed
84

85 86 87 88 89 90 91 92 93 94
    // 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
95
    _pageNeedsUpdate.resize(_ui->tabWidget->count());
96
    connect(_ui->tabWidget, SIGNAL(currentChanged(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
97
            SLOT(preparePage(int)));
98

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
110
    SessionManager::instance()->changeProfile(_profile, _tempProfile->setProperties());
111 112 113

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

120 121
    createTempProfile();

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

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

181 182
    _profile = profile;

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

186 187 188 189 190
    // 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
191
    preparePage(_ui->tabWidget->currentIndex());
192

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
205 206
    Q_ASSERT(_pageNeedsUpdate.count() > page);
    Q_ASSERT(info);
207

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

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

226
        _pageNeedsUpdate[page] = false;
227
    }
Robert Knight's avatar
 
Robert Knight committed
228 229

    // start page entry animation for color schemes
Kurt Hindenburg's avatar
Kurt Hindenburg committed
230 231
    if (pageWidget == _ui->appearanceTab)
        _colorSchemeAnimationTimeLine->start();
Robert Knight's avatar
 
Robert Knight committed
232 233 234 235
}
void EditProfileDialog::selectProfileName()
{
    _ui->profileNameEdit->setFocus();
236
    _ui->profileNameEdit->selectAll();
237
}
238
void EditProfileDialog::setupGeneralPage(const Profile::Ptr info)
239
{
240
    // basic profile options
241
    {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
242 243 244
        ProfileGroup::Ptr group = info->asGroup();
        if (!group || group->profiles().count() < 2) {
            _ui->profileNameEdit->setText(info->name());
245
            _ui->profileNameEdit->setClearButtonShown(true);
246

Kurt Hindenburg's avatar
Kurt Hindenburg committed
247
            _ui->emptyNameWarningWidget->setVisible(info->name().isEmpty());
248
            _ui->emptyNameWarningWidget->setText(i18n("Profile name is empty."));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
249 250
        } else {
            _ui->profileNameEdit->setText(groupProfileNames(group, -1));
251
            _ui->profileNameEdit->setEnabled(false);
252
            _ui->profileNameLabel->setEnabled(false);
253 254

            _ui->emptyNameWarningWidget->setVisible(false);
255 256
        }
    }
257

258

Kurt Hindenburg's avatar
Kurt Hindenburg committed
259 260
    ShellCommand command(info->command() , info->arguments());
    _ui->commandEdit->setText(command.fullCommand());
261
    KUrlCompletion* exeCompletion = new KUrlCompletion(KUrlCompletion::ExeCompletion);
262
    exeCompletion->setParent(this);
263
    exeCompletion->setDir(QString());
Kurt Hindenburg's avatar
Kurt Hindenburg committed
264
    _ui->commandEdit->setCompletionObject(exeCompletion);
265

Kurt Hindenburg's avatar
Kurt Hindenburg committed
266
    _ui->initialDirEdit->setText(info->defaultWorkingDirectory());
267 268
    KUrlCompletion* dirCompletion = new KUrlCompletion(KUrlCompletion::DirCompletion);
    dirCompletion->setParent(this);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
269
    _ui->initialDirEdit->setCompletionObject(dirCompletion);
270
    _ui->initialDirEdit->setClearButtonShown(true);
271

Kurt Hindenburg's avatar
Kurt Hindenburg committed
272 273
    _ui->dirSelectButton->setIcon(KIcon("folder-open"));
    _ui->iconSelectButton->setIcon(KIcon(info->icon()));
274
    _ui->startInSameDirButton->setChecked(info->property<bool>(Profile::StartInCurrentSessionDir));
275

276
    // window options
Kurt Hindenburg's avatar
Kurt Hindenburg committed
277 278 279
    _ui->showMenuBarButton->setChecked(info->property<bool>(Profile::ShowMenuBar));
    _ui->showTerminalSizeHintButton->setChecked(info->property<bool>(Profile::ShowTerminalSizeHint));
    _ui->saveGeometryOnExitButton->setChecked(info->property<bool>(Profile::SaveGeometryOnExit));
280 281

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

295
    connect(_ui->showMenuBarButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
296
            SLOT(showMenuBar(bool)));
297
    connect(_ui->saveGeometryOnExitButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
298
            SLOT(saveGeometryOnExit(bool)));
299
    connect(_ui->showTerminalSizeHintButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
300
            SLOT(showTerminalSizeHint(bool)));
301 302 303
}
void EditProfileDialog::showEnvironmentEditor()
{
304
    const Profile::Ptr info = lookupProfile();
305

Kurt Hindenburg's avatar
Kurt Hindenburg committed
306 307
    QWeakPointer<KDialog> dialog = new KDialog(this);
    KTextEdit* edit = new KTextEdit(dialog.data());
308

309
    QStringList currentEnvironment = info->property<QStringList>(Profile::Environment);
310

Kurt Hindenburg's avatar
Kurt Hindenburg committed
311 312
    edit->setPlainText(currentEnvironment.join("\n"));
    edit->setToolTip(i18n("One environment variable per line"));
313

Kurt Hindenburg's avatar
Kurt Hindenburg committed
314 315
    dialog.data()->setPlainCaption(i18n("Edit Environment"));
    dialog.data()->setMainWidget(edit);
316

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
322
    delete dialog.data();
323
}
324
void EditProfileDialog::setupTabsPage(const Profile::Ptr info)
325
{
326 327 328
    // tab title format
    _ui->tabTitleEdit->setClearButtonShown(true);
    _ui->remoteTabTitleEdit->setClearButtonShown(true);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
329 330 331
    _ui->tabTitleEdit->setText(info->property<QString>(Profile::LocalTabTitleFormat));
    _ui->remoteTabTitleEdit->setText(
        info->property<QString>(Profile::RemoteTabTitleFormat));
332

Jekyll Wu's avatar
Jekyll Wu committed
333
    // tab bar options
Jekyll Wu's avatar
Jekyll Wu committed
334 335
    int tabBarMode = info->property<int>(Profile::TabBarMode);
    int tabBarPosition = info->property<int>(Profile::TabBarPosition);
336
    int newTabBehavior = info->property<int>(Profile::NewTabBehavior);
337

Kurt Hindenburg's avatar
Kurt Hindenburg committed
338
    // note: Items should be in the same order as the
339
    // Profile::TabBarModeEnum enum
Kurt Hindenburg's avatar
Kurt Hindenburg committed
340 341 342
    _ui->tabBarVisibilityCombo->addItems(QStringList() << i18n("Always Hide Tab Bar")
                                         << i18n("Show Tab Bar When Needed")
                                         << i18n("Always Show Tab Bar"));
Jekyll Wu's avatar
Jekyll Wu committed
343
    _ui->tabBarVisibilityCombo->setCurrentIndex(tabBarMode);
344 345 346

    // note: Items should be in the same order as the
    // Profile::TabBarPositionEnum enum
Kurt Hindenburg's avatar
Kurt Hindenburg committed
347 348
    _ui->tabBarPositionCombo->addItems(QStringList() << i18n("Below Terminal Displays")
                                       << i18n("Above Terminal Displays"));
Jekyll Wu's avatar
Jekyll Wu committed
349
    _ui->tabBarPositionCombo->setCurrentIndex(tabBarPosition);
350

351 352
    // note: Items should be in the same order as the
    // Profile::NewTabBehaviorEnum enum
Kurt Hindenburg's avatar
Kurt Hindenburg committed
353 354
    _ui->newTabBehaviorCombo->addItems(QStringList() << i18n("Put New Tab At The End")
                                       << i18n("Put New Tab After Current Tab"));
355 356
    _ui->newTabBehaviorCombo->setCurrentIndex(newTabBehavior);

Robert Knight's avatar
 
Robert Knight committed
357
    _ui->newTabButton->setChecked(info->property<bool>(Profile::ShowNewAndCloseTabButtons));
358

Jekyll Wu's avatar
Jekyll Wu committed
359 360 361 362
    // tab monitoring
    int silenceSeconds = info->property<int>(Profile::SilenceSeconds);
    _ui->silenceSecondsSpinner->setValue(silenceSeconds);

363
    // signals and slots
364
    connect(_ui->tabBarVisibilityCombo, SIGNAL(activated(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
365
            SLOT(tabBarVisibilityChanged(int)));
366
    connect(_ui->tabBarPositionCombo, SIGNAL(activated(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
367
            SLOT(tabBarPositionChanged(int)));
368
    connect(_ui->newTabBehaviorCombo, SIGNAL(activated(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
369
            SLOT(newTabBehaviorChanged(int)));
370
    connect(_ui->newTabButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
371
            SLOT(showNewTabButton(bool)));
372

373
    connect(_ui->tabTitleEdit, SIGNAL(textChanged(QString)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
374
            SLOT(tabTitleFormatChanged(QString)));
375
    connect(_ui->remoteTabTitleEdit, SIGNAL(textChanged(QString)), this,
Laurent Montel's avatar
Laurent Montel committed
376
            SLOT(remoteTabTitleFormatChanged(QString)));
377

378 379
    connect(_ui->silenceSecondsSpinner, SIGNAL(valueChanged(int)),
            this, SLOT(silenceSecondsChanged(int)));
380

381 382 383 384
    // menus for local and remote tab title dynamic elements
    TabTitleFormatAction* localTabTitleAction = new TabTitleFormatAction(this);
    localTabTitleAction->setContext(Session::LocalTabTitle);
    _ui->tabTitleEditButton->setMenu(localTabTitleAction->menu());
385 386
    connect(localTabTitleAction, SIGNAL(dynamicElementSelected(QString)),
            this, SLOT(insertTabTitleText(QString)));
387 388 389 390

    TabTitleFormatAction* remoteTabTitleAction = new TabTitleFormatAction(this);
    remoteTabTitleAction->setContext(Session::RemoteTabTitle);
    _ui->remoteTabTitleEditButton->setMenu(remoteTabTitleAction->menu());
391 392
    connect(remoteTabTitleAction, SIGNAL(dynamicElementSelected(QString)),
            this, SLOT(insertRemoteTabTitleText(QString)));
393
}
394
void EditProfileDialog::showNewTabButton(bool show)
395
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
396
    updateTempProfileProperty(Profile::ShowNewAndCloseTabButtons, show);
397
}
398 399
void EditProfileDialog::tabBarVisibilityChanged(int newValue)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
400
    updateTempProfileProperty(Profile::TabBarMode , newValue);
401 402 403
}
void EditProfileDialog::tabBarPositionChanged(int newValue)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
404
    updateTempProfileProperty(Profile::TabBarPosition , newValue);
405
}
406 407
void EditProfileDialog::newTabBehaviorChanged(int newValue)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
408
    updateTempProfileProperty(Profile::NewTabBehavior , newValue);
409
}
410 411 412 413 414 415 416 417
void EditProfileDialog::insertTabTitleText(const QString& text)
{
    _ui->tabTitleEdit->insert(text);
}
void EditProfileDialog::insertRemoteTabTitleText(const QString& text)
{
    _ui->remoteTabTitleEdit->insert(text);
}
418 419
void EditProfileDialog::showMenuBar(bool show)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
420
    updateTempProfileProperty(Profile::ShowMenuBar, show);
421
}
422 423
void EditProfileDialog::saveGeometryOnExit(bool save)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
424
    updateTempProfileProperty(Profile::SaveGeometryOnExit, save);
425
}
426
void EditProfileDialog::showTerminalSizeHint(bool show)
427
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
428
    updateTempProfileProperty(Profile::ShowTerminalSizeHint, show);
429
}
430 431
void EditProfileDialog::tabTitleFormatChanged(const QString& format)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
432
    updateTempProfileProperty(Profile::LocalTabTitleFormat, format);
433 434 435
}
void EditProfileDialog::remoteTabTitleFormatChanged(const QString& format)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
436
    updateTempProfileProperty(Profile::RemoteTabTitleFormat, format);
437 438
}

439 440 441 442 443
void EditProfileDialog::silenceSecondsChanged(int seconds)
{
    updateTempProfileProperty(Profile::SilenceSeconds, seconds);
}

444 445
void EditProfileDialog::selectIcon()
{
Craig Drummond's avatar
Craig Drummond committed
446
    const QString& icon = KIconDialog::getIcon(KIconLoader::Desktop, KIconLoader::Application,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
447 448 449 450
                          false, 0, false, this);
    if (!icon.isEmpty()) {
        _ui->iconSelectButton->setIcon(KIcon(icon));
        updateTempProfileProperty(Profile::Icon, icon);
451 452 453 454
    }
}
void EditProfileDialog::profileNameChanged(const QString& text)
{
455 456
    _ui->emptyNameWarningWidget->setVisible(text.isEmpty());

Kurt Hindenburg's avatar
Kurt Hindenburg committed
457
    updateTempProfileProperty(Profile::Name, text);
458
    updateCaption(_tempProfile);
459
}
460 461
void EditProfileDialog::startInSameDir(bool sameDir)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
462
    updateTempProfileProperty(Profile::StartInCurrentSessionDir, sameDir);
463
}
464 465
void EditProfileDialog::initialDirChanged(const QString& dir)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
466
    updateTempProfileProperty(Profile::Directory, dir);
467 468 469
}
void EditProfileDialog::commandChanged(const QString& command)
{
470 471
    ShellCommand shellCommand(command);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
472 473
    updateTempProfileProperty(Profile::Command, shellCommand.command());
    updateTempProfileProperty(Profile::Arguments, shellCommand.arguments());
474 475 476
}
void EditProfileDialog::selectInitialDir()
{
477
    const KUrl url = KFileDialog::getExistingDirectoryUrl(_ui->initialDirEdit->text(),
Kurt Hindenburg's avatar
Kurt Hindenburg committed
478 479
                     this,
                     i18n("Select Initial Directory"));
480

Kurt Hindenburg's avatar
Kurt Hindenburg committed
481
    if (!url.isEmpty())
482
        _ui->initialDirEdit->setText(url.path());
483
}
484
void EditProfileDialog::setupAppearancePage(const Profile::Ptr info)
485
{
486
    ColorSchemeViewDelegate* delegate = new ColorSchemeViewDelegate(this);
487
    _ui->colorSchemeList->setItemDelegate(delegate);
488

Kurt Hindenburg's avatar
Kurt Hindenburg committed
489
    _colorSchemeAnimationTimeLine = new QTimeLine(500 , this);
Robert Knight's avatar
 
Robert Knight committed
490
    delegate->setEntryTimeLine(_colorSchemeAnimationTimeLine);
491

492
    connect(_colorSchemeAnimationTimeLine, SIGNAL(valueChanged(qreal)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
493
            SLOT(colorSchemeAnimationUpdate()));
494

Robert Knight's avatar
 
Robert Knight committed
495
    _ui->transparencyWarningWidget->setVisible(false);
496

Robert Knight's avatar
 
Robert Knight committed
497 498 499
    _ui->editColorSchemeButton->setEnabled(false);
    _ui->removeColorSchemeButton->setEnabled(false);

500 501
    // setup color list
    updateColorSchemeList(true);
502

503 504
    _ui->colorSchemeList->setMouseTracking(true);
    _ui->colorSchemeList->installEventFilter(this);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
505
    _ui->colorSchemeList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
506

507 508 509 510
    connect(_ui->colorSchemeList->selectionModel(),
            SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(colorSchemeSelected()));
    connect(_ui->colorSchemeList, SIGNAL(entered(QModelIndex)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
511
            SLOT(previewColorScheme(QModelIndex)));
512

Robert Knight's avatar
 
Robert Knight committed
513
    updateColorSchemeButtons();
514

515
    connect(_ui->editColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
516
            SLOT(editColorScheme()));
517
    connect(_ui->removeColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
518
            SLOT(removeColorScheme()));
519
    connect(_ui->newColorSchemeButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
520
            SLOT(newColorScheme()));
521

522
    // setup font preview
523
    bool antialias = info->property<bool>(Profile::AntiAliasFonts);
524 525

    QFont font = info->font();
526
    font.setStyleStrategy(antialias ? QFont::PreferAntialias : QFont::NoAntialias);
527

528 529
    _ui->fontPreviewLabel->installEventFilter(this);
    _ui->fontPreviewLabel->setFont(font);
530 531
    setFontSliderRange(font);
    setFontSliderValue(font);
532

533
    connect(_ui->fontSizeSlider, SIGNAL(valueChanged(int)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
534
            SLOT(setFontSize(int)));
535
    connect(_ui->editFontButton, SIGNAL(clicked()), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
536
            SLOT(showFontDialog()));
537

Kurt Hindenburg's avatar
Kurt Hindenburg committed
538
    // setup font smoothing
539
    _ui->antialiasTextButton->setChecked(antialias);
540
    connect(_ui->antialiasTextButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
541
            SLOT(setAntialiasText(bool)));
542 543 544

    bool boldIntense = info->property<bool>(Profile::BoldIntense);
    _ui->boldIntenseButton->setChecked(boldIntense);
545
    connect(_ui->boldIntenseButton, SIGNAL(toggled(bool)), this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
546
            SLOT(setBoldIntense(bool)));
547 548 549
}
void EditProfileDialog::setAntialiasText(bool enable)
{
550 551 552
    QFont font = _ui->fontPreviewLabel->font();
    font.setStyleStrategy(enable ? QFont::PreferAntialias : QFont::NoAntialias);

553
    // update preview to reflect text smoothing state
554
    fontSelected(font);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
555
    updateTempProfileProperty(Profile::AntiAliasFonts, enable);
556
}
557 558
void EditProfileDialog::setBoldIntense(bool enable)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
559 560
    preview(Profile::BoldIntense, enable);
    updateTempProfileProperty(Profile::BoldIntense, enable);
561
}
562 563 564 565
void EditProfileDialog::colorSchemeAnimationUpdate()
{
    QAbstractItemModel* model = _ui->colorSchemeList->model();

Kurt Hindenburg's avatar
Kurt Hindenburg committed
566 567
    for (int i = model->rowCount() ; i >= 0 ; i--)
        _ui->colorSchemeList->update(model->index(i, 0));
568
}
569
void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
570
{
Robert Knight's avatar
 
Robert Knight committed
571 572
    if (!_ui->colorSchemeList->model())
        _ui->colorSchemeList->setModel(new QStandardItemModel(this));
573

574
    const QString& name = lookupProfile()->colorScheme();
575 576
    const ColorScheme* currentScheme = ColorSchemeManager::instance()->findColorScheme(name);

Robert Knight's avatar
 
Robert Knight committed
577 578 579
    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->colorSchemeList->model());

    Q_ASSERT(model);
580

Robert Knight's avatar
 
Robert Knight committed
581 582
    model->clear();

583 584 585
    QList<const ColorScheme*> schemeList = ColorSchemeManager::instance()->allColorSchemes();
    QListIterator<const ColorScheme*> schemeIter(schemeList);

586 587
    QStandardItem* selectedItem = 0;

Kurt Hindenburg's avatar
Kurt Hindenburg committed
588
    while (schemeIter.hasNext()) {
589 590
        const ColorScheme* colors = schemeIter.next();
        QStandardItem* item = new QStandardItem(colors->description());
Kurt Hindenburg's avatar
Kurt Hindenburg committed
591 592
        item->setData(QVariant::fromValue(colors) ,  Qt::UserRole + 1);
        item->setFlags(item->flags());
593

Kurt Hindenburg's avatar
Kurt Hindenburg committed
594 595
        if (currentScheme == colors)
            selectedItem = item;
Robert Knight's avatar
 
Robert Knight committed
596

597 598 599
        model->appendRow(item);
    }

600 601
    model->sort(0);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
602
    if (selectCurrentScheme && selectedItem) {
603
        _ui->colorSchemeList->updateGeometry();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
604 605
        _ui->colorSchemeList->selectionModel()->setCurrentIndex(selectedItem->index() ,
                QItemSelectionModel::Select);
Robert Knight's avatar
 
Robert Knight committed
606 607 608

        // update transparency warning label
        updateTransparencyWarning();
609
    }
610
}
611
void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
612
{
Robert Knight's avatar
 
Robert Knight committed
613 614
    if (!_ui->keyBindingList->model())
        _ui->keyBindingList->setModel(new QStandardItemModel(this));
615

616
    const QString& name = lookupProfile()
Kurt Hindenburg's avatar
Kurt Hindenburg committed
617
                          ->property<QString>(Profile::KeyBindings);
618

619
    KeyboardTranslatorManager* keyManager = KeyboardTranslatorManager::instance();
620
    const KeyboardTranslator* currentTranslator = keyManager->findTranslator(name);
621

Robert Knight's avatar
 
Robert Knight committed
622 623 624 625 626
    QStandardItemModel* model = qobject_cast<QStandardItemModel*>(_ui->keyBindingList->model());

    Q_ASSERT(model);

    model->clear();
627

628 629
    QStandardItem* selectedItem = 0;

630
    QList<QString> translatorNames = keyManager->allTranslators();
631
    QListIterator<QString> iter(translatorNames);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
632
    while (iter.hasNext()) {
633 634
        const QString& name = iter.next();

635
        const KeyboardTranslator* translator = keyManager->findTranslator(name);
636 637

        QStandardItem* item = new QStandardItem(translator->description());
Kurt Hindenburg's avatar
Kurt Hindenburg committed
638 639
        item->setData(QVariant::fromValue(translator), Qt::UserRole + 1);
        item->setIcon(KIcon("preferences-desktop-keyboard"));
640

Kurt Hindenburg's avatar
Kurt Hindenburg committed
641
        if (translator == currentTranslator)
642
            selectedItem = item;
643 644 645 646

        model->appendRow(item);
    }

647
    model->sort(0);
648

Kurt Hindenburg's avatar
Kurt Hindenburg committed
649 650 651
    if (selectCurrentTranslator && selectedItem) {
        _ui->keyBindingList->selectionModel()->setCurrentIndex(selectedItem->index() ,
                QItemSelectionModel::Select);
652
    }
653
}
Kurt Hindenburg's avatar
Kurt Hindenburg committed
654
bool EditProfileDialog::eventFilter(QObject* watched , QEvent* event)
655
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
656 657 658
    if (watched == _ui->colorSchemeList && event->type() == QEvent::Leave) {
        if (_tempProfile->isPropertySet(Profile::ColorScheme))
            preview(Profile::ColorScheme, _tempProfile->colorScheme());
659 660
        else
            unpreview(Profile::ColorScheme);
661
    }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
662
    if (watched == _ui->fontPreviewLabel && event->type() == QEvent::FontChange) {
663
        const QFont& labelFont = _ui->fontPreviewLabel->font();
664
        qreal size = labelFont.pointSizeF();
Kurt Hindenburg's avatar