juk.cpp 21.5 KB
Newer Older
1 2 3 4 5
/***************************************************************************
                          juk.cpp  -  description
                             -------------------
    begin                : Mon Feb  4 23:40:41 EST 2002
    copyright            : (C) 2002 by Scott Wheeler
6
    email                : wheeler@kde.org
7
***************************************************************************/
8 9 10 11 12 13 14 15 16 17

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

18 19 20 21 22 23 24
#include <kcmdlineargs.h>
#include <kstatusbar.h>
#include <kdebug.h>
#include <kmessagebox.h>

#include <qslider.h>

25 26 27 28 29 30 31
#include "juk.h"
#include "slideraction.h"
#include "statuslabel.h"
#include "splashscreen.h"
#include "systemtray.h"
#include "keydialog.h"
#include "tagguesserconfigdlg.h"
32
#include "filerenamerconfigdlg.h"
33
#include "actioncollection.h"
34
#include "cache.h"
35

36 37
using namespace ActionCollection;

38 39 40 41
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////

Scott Wheeler's avatar
Scott Wheeler committed
42 43
JuK::JuK(QWidget *parent, const char *name) :
    KMainWindow(parent, name, WDestructiveClose),
44
    m_player(PlayerManager::instance()),
45
    m_shuttingDown(false)
46
{
47 48
    // Expect segfaults if you change this order.

49
    readSettings();
50

51
    if(m_showSplash && !m_startDocked) {
52 53 54 55
	SplashScreen::instance()->show();
	kapp->processEvents();
    }

56
    setupActions();
57 58
    setupLayout();
    setupSplitterConnections();
59
    slotPlaylistChanged();
60
    readConfig();
61
    setupSystemTray();
62
    setupGlobalAccels();
63
    processArgs();
64

65 66
    m_player->setPlaylistInterface(m_splitter);

67
    SplashScreen::finishedLoading();
Scott Wheeler's avatar
Scott Wheeler committed
68
    QTimer::singleShot(0, CollectionList::instance(), SLOT(slotCheckCache()));
69 70

    m_sliderAction->slotUpdateOrientation();
71 72 73 74
}

JuK::~JuK()
{
75

76 77
}

78 79 80 81 82
KActionCollection *JuK::actionCollection() const
{
    return ActionCollection::actions();
}

83 84 85 86
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////

87
void JuK::slotGuessTagInfoFromFile()
88
{
89 90 91 92 93 94
    m_splitter->slotGuessTagInfo(TagGuesser::FileName);
}

void JuK::slotGuessTagInfoFromInternet()
{
    m_splitter->slotGuessTagInfo(TagGuesser::MusicBrainz);
95 96
}

97 98 99 100 101
void JuK::openFile(const QString &file)
{
    m_splitter->open(file);
}

102 103 104 105 106 107
void JuK::openFile(const QStringList &files)
{
    for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
	openFile(*it);
}

108 109 110 111
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

112 113
void JuK::setupLayout()
{
114
    m_splitter = new PlaylistSplitter(this, "playlistSplitter");
115
    setCentralWidget(m_splitter);
116 117

    // playlist item activation connection
Scott Wheeler's avatar
Scott Wheeler committed
118
    connect(m_splitter, SIGNAL(signalActivated()),
119
	    this, SLOT(slotPlayCurrent()));
Scott Wheeler's avatar
Scott Wheeler committed
120
    connect(m_splitter, SIGNAL(signalListBoxDoubleClicked()),
121
	    this, SLOT(slotPlayCurrent()));
122

123
    // create status bar
124

125
    m_statusLabel = new StatusLabel(statusBar());
126

127
    statusBar()->addWidget(m_statusLabel, 1);
128

Scott Wheeler's avatar
Scott Wheeler committed
129 130
    connect(m_splitter, SIGNAL(signalSelectedPlaylistCountChanged(int)),
	    m_statusLabel, SLOT(setPlaylistCount(int)));
131 132
    connect(m_splitter, SIGNAL(signalSelectedPlaylistTimeChanged(int)),
	    m_statusLabel, SLOT(setPlaylistTime(int)));
Scott Wheeler's avatar
Scott Wheeler committed
133 134
    connect(m_statusLabel, SIGNAL(jumpButtonClicked()),
	    m_splitter, SLOT(slotSelectPlaying()));
135

136 137
    PlayerManager::instance()->setStatusLabel(m_statusLabel);

138 139
    // Needs to be here because m_splitter is not called before setupActions
    // (because PlaylistSplitter itself accesses the actionCollection)
140

141
    new KAction(i18n("&Rename File"), 0, "CTRL+r", m_splitter, SLOT(slotRenameFile()),
142
                actions(), "renameFile"); // 4
143

144
    m_splitter->setFocus();
145

146
    resize(750, 500);
147 148
}

149 150
void JuK::setupActions()
{
151
    //////////////////////////////////////////////////
152
    // file menu
153
    //////////////////////////////////////////////////
154

Scott Wheeler's avatar
Scott Wheeler committed
155
    KActionMenu *newMenu = new KActionMenu(i18n("&New"), "filenew",
156
					   actions(), "file_new");
Scott Wheeler's avatar
Scott Wheeler committed
157

158 159 160 161 162 163
    // This connection will call the
    // PlaylistSplitter::slotCreatePlaylist(const QString &) slot - this is
    // possible because the QString parameter has a default value, so the
    // slot can be called without arguments (as required by the signal's
    // signature).

Scott Wheeler's avatar
Scott Wheeler committed
164 165 166
    newMenu->insert(createSplitterAction(i18n("Empty Playlist..."),
					 SLOT(slotCreatePlaylist()), 0, 0, 0));

167
    newMenu->insert(createSplitterAction(i18n("Playlist From Folder..."),
Scott Wheeler's avatar
Scott Wheeler committed
168 169
					 SLOT(slotCreatePlaylistFromDir()), 0, 0, 0));

170 171 172 173 174 175 176 177
    createSplitterAction(i18n("Open..."),         SLOT(slotOpen()),              "file_open", "fileopen", "CTRL+o");
    createSplitterAction(i18n("Open &Folder..."), SLOT(slotOpenDirectory()),     "openDirectory", "fileopen");
    createSplitterAction(i18n("&Rename..."),      SLOT(slotRenamePlaylist()),    "renamePlaylist");
    createSplitterAction(i18n("D&uplicate..."),   SLOT(slotDuplicatePlaylist()), "duplicatePlaylist");
    createSplitterAction(i18n("Save"),            SLOT(slotSavePlaylist()),      "file_save", "filesave", "CTRL+s");
    createSplitterAction(i18n("Save As..."),      SLOT(slotSaveAsPlaylist()),    "file_save_as", "filesaveas");
    createSplitterAction(i18n("R&emove"),         SLOT(slotDeletePlaylist()),    "deleteItemPlaylist", "edittrash");
    createSplitterAction(i18n("Reload"),          SLOT(slotReloadPlaylist()),    "reloadPlaylist", "reload");
178

179
    KStdAction::quit(this, SLOT(slotQuit()), actions());
180

181
    //////////////////////////////////////////////////
182
    // edit menu
183 184
    //////////////////////////////////////////////////

185 186 187 188
    KStdAction::cut(kapp,   SLOT(cut()),   actions());
    KStdAction::copy(kapp,  SLOT(copy()),  actions());
    KStdAction::paste(kapp, SLOT(paste()), actions());
    KStdAction::clear(kapp, SLOT(clear()), actions());
189

190
    KStdAction::selectAll(kapp, SLOT(selectAll()), actions());
191

192
    createSplitterAction(
193
	i18n("Advanced Search"), SLOT(slotAdvancedSearch()), "advancedSearch", "find", "s");
194

195
    //////////////////////////////////////////////////
196
    // view menu
197
    //////////////////////////////////////////////////
198

Scott Wheeler's avatar
Scott Wheeler committed
199
    m_showSearchAction = new KToggleAction(i18n("Show &Search Bar"), "filefind",
200
					   0, actions(), "showSearch");
Scott Wheeler's avatar
Scott Wheeler committed
201
    m_showEditorAction = new KToggleAction(i18n("Show &Tag Editor"), "edit",
202
					   0, actions(), "showEditor");
203
    m_showHistoryAction = new KToggleAction(i18n("Show &History"), "history",
204
					   0, actions(), "showHistory");
205

206
    createSplitterAction(i18n("Refresh Items"), SLOT(slotRefresh()), "refresh", "reload");
207

208
    //////////////////////////////////////////////////
209
    // play menu
210 211
    //////////////////////////////////////////////////

Scott Wheeler's avatar
Scott Wheeler committed
212
    m_randomPlayAction = new KToggleAction(i18n("&Random Play"), 0,
213
					   actions(), "randomPlay");
Scott Wheeler's avatar
Scott Wheeler committed
214

215 216 217
    new KAction(i18n("&Play"),  "player_play",  0, m_player, SLOT(play()),  actions(), "play");
    new KAction(i18n("P&ause"), "player_pause", 0, m_player, SLOT(pause()), actions(), "pause");
    new KAction(i18n("&Stop"),  "player_stop",  0, m_player, SLOT(stop()),  actions(), "stop");
Scott Wheeler's avatar
Scott Wheeler committed
218

219 220 221 222
    // m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
    //                                        this, SLOT(back()), actions(), "back");

    // TODO: switch this back to being a popup action
223

224 225
    new KAction(i18n("Previous& Track"), "player_start", 0, m_player, SLOT(back()),    actions(), "back");
    new KAction(i18n("&Next Track"),     "player_end",   0, m_player, SLOT(forward()), actions(), "forward");
226

227 228 229
    new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist");

    // the following are not visible by default
230

231 232 233 234 235 236 237
    new KAction(i18n("Mute"),         "mute",        0, m_player, SLOT(mute()),        actions(), "mute");
    new KAction(i18n("Volume Up"),    "volumeUp",    0, m_player, SLOT(volumeUp()),    actions(), "volumeUp");
    new KAction(i18n("Volume Down"),  "volumeDown",  0, m_player, SLOT(volumeDown()),  actions(), "volumeDown");
    new KAction(i18n("Play / Pause"), "playPause",   0, m_player, SLOT(playPause()),   actions(), "playPause");
    new KAction(i18n("Seek Forward"), "seekForward", 0, m_player, SLOT(seekForward()), actions(), "seekForward");
    new KAction(i18n("Seek Back"),    "seekBack",    0, m_player, SLOT(seekBack()),    actions(), "seekBack");
    
238

239
    //////////////////////////////////////////////////
240
    // tagger menu
241 242
    //////////////////////////////////////////////////

243
    createSplitterAction(i18n("&Save"), SLOT(slotSaveTag()),
Scott Wheeler's avatar
Scott Wheeler committed
244 245 246
			 "saveItem",   "filesave", "CTRL+t");
    createSplitterAction(i18n("&Delete"), SLOT(slotDeleteSelectedItems()),
			 "removeItem", "editdelete");
247

248 249
    KActionMenu *guessMenu = new KActionMenu(i18n("&Guess Tag Information"),
					     QString::null, actions(),
Scott Wheeler's avatar
Scott Wheeler committed
250
					     "guessTag");
251

252 253 254
    guessMenu->insert(
	new KAction(i18n("From &Filename"), 0, "CTRL+f", this, SLOT(slotGuessTagInfoFromFile()),
		    actions(), "guessTagFile"));
255
#if HAVE_MUSICBRAINZ
256 257 258
    guessMenu->insert(
	new KAction(i18n("From &Internet"), 0, "CTRL+i", this, SLOT(slotGuessTagInfoFromInternet()),
		    actions(), "guessTagInternet"));
259
#endif
Scott Wheeler's avatar
Scott Wheeler committed
260

261
    //////////////////////////////////////////////////
262
    // settings menu
263 264
    //////////////////////////////////////////////////

265
    setStandardToolBarMenuEnabled(true);
266

Stephan Binner's avatar
Stephan Binner committed
267
    m_toggleSplashAction = new KToggleAction(i18n("Show Splash Screen on Startup"),
268
					     0, actions(), "showSplashScreen");
Scott Wheeler's avatar
Scott Wheeler committed
269 270

    m_toggleSystemTrayAction = new KToggleAction(i18n("&Dock in System Tray"),
271
						 0, actions(), "toggleSystemTray");
Scott Wheeler's avatar
Scott Wheeler committed
272 273

    m_toggleDockOnCloseAction = new KToggleAction(i18n("&Stay in System Tray on Close"),
274
						  0, actions(), "dockOnClose");
275

276
    m_togglePopupsAction = new KToggleAction(i18n("Popup &Track Announcement"),
277
					     0, this, 0, actions(), "togglePopups");
278

Scott Wheeler's avatar
Scott Wheeler committed
279 280
    connect(m_toggleSystemTrayAction, SIGNAL(toggled(bool)),
	    this, SLOT(slotToggleSystemTray(bool)));
281

Scott Wheeler's avatar
Scott Wheeler committed
282

283
    m_outputSelectAction = PlayerManager::playerSelectAction(actions());
284

285
    if(m_outputSelectAction)
286
        m_outputSelectAction->setCurrentItem(0);
287

Scott Wheeler's avatar
Scott Wheeler committed
288
    new KAction(i18n("&Tag Guesser..."), 0, 0, this, SLOT(slotConfigureTagGuesser()),
289
		actions(), "tagGuesserConfig");
290

291
    new KAction(i18n("&File Renamer..."), 0, 0, this, SLOT(slotConfigureFileRenamer()),
292
		actions(), "fileRenamerConfig");
293

294
    KStdAction::keyBindings(this, SLOT(slotEditKeys()), actions());
295

296
    //////////////////////////////////////////////////
297
    // just in the toolbar
298 299
    //////////////////////////////////////////////////

300
    m_sliderAction = new SliderAction(i18n("Track Position"), actions(),
Scott Wheeler's avatar
Scott Wheeler committed
301
				      "trackPositionAction");
302 303

    createGUI();
304 305
}

306 307 308 309 310 311
void JuK::setupSplitterConnections()
{
    QValueListConstIterator<SplitterConnection> it = m_splitterConnections.begin();
    for(; it != m_splitterConnections.end(); ++it)
        connect((*it).first, SIGNAL(activated()), m_splitter, (*it).second);

Scott Wheeler's avatar
Scott Wheeler committed
312 313 314 315
    connect(m_showSearchAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetSearchVisible(bool)));
    connect(m_showEditorAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetEditorVisible(bool)));
316 317
    connect(m_showHistoryAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetHistoryVisible(bool)));
318
    connect(this, SIGNAL(dockWindowPositionChanged(QDockWindow *)),
Scott Wheeler's avatar
Scott Wheeler committed
319 320 321
	    m_sliderAction, SLOT(slotUpdateOrientation(QDockWindow *)));
    connect(m_splitter, SIGNAL(signalPlaylistChanged()),
	    this, SLOT(slotPlaylistChanged()));
322 323
}

324
void JuK::setupSystemTray()
325
{
326
    if(m_toggleSystemTrayAction && m_toggleSystemTrayAction->isChecked()) {
327 328
        m_systemTray = new SystemTray(this, "systemTray");
        m_systemTray->show();
329

330
        connect(this, SIGNAL(signalNewSong(const QString&)),
Scott Wheeler's avatar
Scott Wheeler committed
331
		m_systemTray, SLOT(slotNewSong(const QString&)));
332

333
        m_toggleDockOnCloseAction->setEnabled(true);
334
	m_togglePopupsAction->setEnabled(true);
335

336
        connect(m_systemTray, SIGNAL(quitSelected()), this, SLOT(slotQuit()));
337
    }
338
    else {
339 340
        m_systemTray = 0;
        m_toggleDockOnCloseAction->setEnabled(false);
341
	m_togglePopupsAction->setEnabled(false);
342
    }
343 344
}

345 346 347
void JuK::setupGlobalAccels()
{
    m_accel = new KGlobalAccel(this);
348

349 350 351 352 353 354 355 356 357
    KeyDialog::insert(m_accel, "PlayPause",   i18n("Play / Pause"), action("playPause"),   SLOT(activate()));
    KeyDialog::insert(m_accel, "Stop",        i18n("Stop Playing"), action("stop"),        SLOT(activate()));
    KeyDialog::insert(m_accel, "Back",        i18n("Back"),         action("back"),        SLOT(activate()));
    KeyDialog::insert(m_accel, "Forward",     i18n("Forward"),      action("forward"),     SLOT(activate()));
    KeyDialog::insert(m_accel, "SeekBack",    i18n("Seek Back"),    action("seekBack"),    SLOT(activate()));
    KeyDialog::insert(m_accel, "SeekForward", i18n("Seek Forward"), action("seekForward"), SLOT(activate()));
    KeyDialog::insert(m_accel, "VolumeUp",    i18n("Volume Up"),    action("volumeUp"),    SLOT(activate()));
    KeyDialog::insert(m_accel, "VolumeDown",  i18n("Volume Down"),  action("volumeDown"),  SLOT(activate()));
    KeyDialog::insert(m_accel, "Mute",        i18n("Mute"),         action("mute"),        SLOT(activate()));
358
    KeyDialog::insert(m_accel, "ShowHide",    i18n("Show / Hide"),  this,                  SLOT(slotShowHide()));
359

360 361 362 363 364
    m_accel->setConfigGroup("Shortcuts");
    m_accel->readSettings();
    m_accel->updateConnections();
}

365 366 367 368
void JuK::processArgs()
{
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    QStringList files;
369

370
    for(int i = 0; i < args->count(); i++)
371
        files.append(args->arg(i));
372

373
    m_splitter->open(files);
374 375
}

376 377 378
void JuK::keyPressEvent(QKeyEvent *e)
{
    if (e->key() >= Qt::Key_Back && e->key() <= Qt::Key_MediaLast)
379
        e->accept();
380 381 382
    KMainWindow::keyPressEvent(e);
}

383 384 385 386 387 388 389 390 391
/**
 * These are settings that need to be know before setting up the GUI.
 */

void JuK::readSettings()
{
    KConfig *config = KGlobal::config();
    { // general settings
        KConfigGroupSaver saver(config, "Settings");
392
        m_showSplash = config->readBoolEntry("ShowSplashScreen", true);
393
        m_startDocked = config->readBoolEntry("StartDocked", false);
394 395 396
    }
}

397 398
void JuK::readConfig()
{
399
    // Automagically save and m_restore many window settings.
400 401
    setAutoSaveSettings();

402
    KConfig *config = KGlobal::config();
403
    { // player settings
404
        KConfigGroupSaver saver(config, "Player");
405 406
        if(m_sliderAction->volumeSlider()) {
	    int maxVolume = m_sliderAction->volumeSlider()->maxValue();
Scott Wheeler's avatar
Scott Wheeler committed
407
	    int volume = config->readNumEntry("Volume", maxVolume);
408
            m_sliderAction->volumeSlider()->setVolume(volume);
409
        }
410 411
        bool randomPlay = config->readBoolEntry("RandomPlay", false);
        m_randomPlayAction->setChecked(randomPlay);
412

413
        bool loopPlaylist = config->readBoolEntry("LoopPlaylist", false);
414
        ActionCollection::action<KToggleAction>("loopPlaylist")->setChecked(loopPlaylist);
415
    }
416
    { // view settings
417
        KConfigGroupSaver saver(config, "View");
418 419 420 421 422

        bool showSearch = config->readBoolEntry("ShowSearch", true);
        m_showSearchAction->setChecked(showSearch);
        m_splitter->slotSetSearchVisible(showSearch);

423 424 425
        bool showEditor = config->readBoolEntry("ShowEditor", false);
        m_showEditorAction->setChecked(showEditor);
        m_splitter->slotSetEditorVisible(showEditor);
426

427 428 429
	// The history list will actually be created by the playlist restoration
	// code, but we want to remember the checkbox's setting and hope that
	// it's in synch with the code that does the real work.
430

431 432
	bool showHistory = config->readBoolEntry("ShowHistory", false);
	m_showHistoryAction->setChecked(showHistory);
433
    }
434 435
    { // general settings
        KConfigGroupSaver saver(config, "Settings");
436

437 438
        bool dockInSystemTray = config->readBoolEntry("DockInSystemTray", true);
        m_toggleSystemTrayAction->setChecked(dockInSystemTray);
439

440 441
        bool dockOnClose = config->readBoolEntry("DockOnClose", true);
        m_toggleDockOnCloseAction->setChecked(dockOnClose);
442

443 444
        bool showPopups = config->readBoolEntry("TrackPopup", false);
        m_togglePopupsAction->setChecked(showPopups);
445

446 447
        if(m_outputSelectAction)
            m_outputSelectAction->setCurrentItem(config->readNumEntry("MediaSystem", 0));
448
    }
449

450
    m_toggleSplashAction->setChecked(m_showSplash);
451 452 453 454
}

void JuK::saveConfig()
{
455
    KConfig *config = KGlobal::config();
456
    { // player settings
457
        KConfigGroupSaver saver(config, "Player");
458
	config->writeEntry("Volume", m_sliderAction->volumeSlider()->volume());
459 460 461 462
	config->writeEntry("RandomPlay", m_randomPlayAction->isChecked());

	KToggleAction *a = ActionCollection::action<KToggleAction>("loopPlaylist");
	config->writeEntry("LoopPlaylist", a->isChecked());
463
    }
464 465
    { // view settings
        KConfigGroupSaver saver(config, "View");
466

467
        config->writeEntry("ShowEditor", m_showEditorAction->isChecked());
468
        config->writeEntry("ShowSearch", m_showSearchAction->isChecked());
469
	config->writeEntry("ShowHistory", m_showHistoryAction->isChecked());
470
    }
471 472
    { // general settings
        KConfigGroupSaver saver(config, "Settings");
473
        config->writeEntry("ShowSplashScreen", m_toggleSplashAction->isChecked());
474
        config->writeEntry("StartDocked", m_startDocked);
475 476 477 478 479
        config->writeEntry("DockInSystemTray", m_toggleSystemTrayAction->isChecked());
        config->writeEntry("DockOnClose", m_toggleDockOnCloseAction->isChecked());
        config->writeEntry("TrackPopup", m_togglePopupsAction->isChecked());
        if(m_outputSelectAction)
            config->writeEntry("MediaSystem", m_outputSelectAction->currentItem());
480
    }
481
    config->sync();
482 483
}

484
bool JuK::queryExit()
485
{
486 487
    m_startDocked = !isVisible();

488
    hide();
489
    action("stop")->activate();
490 491 492
    delete m_systemTray;
    m_systemTray = 0;

493
    Cache::instance()->save();
494
    saveConfig();
495
    delete m_splitter;
496
    return true;
497 498
}

499 500
bool JuK::queryClose()
{
501 502 503 504 505
    if(!m_shuttingDown &&
       !kapp->sessionSaving() &&
       m_systemTray &&
       m_toggleDockOnCloseAction->isChecked())
    {
506
	KMessageBox::information(this,
Scott Wheeler's avatar
Scott Wheeler committed
507 508 509
	    i18n("<qt>Closing the main window will keep JuK running in the system tray. "
		 "Use Quit from the File menu to quit the application.</qt>"),
	    i18n("Docking in System Tray"), "hideOnCloseInfo");
510 511 512 513 514 515 516
	hide();
	return false;
    }
    else
	return true;
}

517 518
void JuK::updatePlaylistInfo()
{
Scott Wheeler's avatar
Scott Wheeler committed
519
    m_statusLabel->setPlaylistInfo(m_splitter->visiblePlaylistName(),
520 521
				   m_splitter->selectedPlaylistCount(),
				   m_splitter->selectedPlaylistTotalTime());
522 523
}

Scott Wheeler's avatar
Scott Wheeler committed
524 525 526
KAction *JuK::createSplitterAction(const QString &text, const char *slot,
				   const char *name, const QString &pix,
				   const KShortcut &shortcut)
527 528 529 530
{
    KAction *action;

    if(pix.isNull())
531
	action = new KAction(text, shortcut, actions(), name);
532
    else
533
	action = new KAction(text, pix, shortcut, actions(), name);
534 535

    m_splitterConnections.append(SplitterConnection(action, slot));
536

537 538 539
    return action;
}

540 541 542 543
////////////////////////////////////////////////////////////////////////////////
// private slot definitions
////////////////////////////////////////////////////////////////////////////////

544 545 546 547 548
void JuK::slotShowHide()
{
    setShown(!isShown());
}

549
void JuK::slotPlaylistChanged()
550
{
551 552 553 554
    if(m_splitter->collectionListSelected() ||
       !m_splitter->hasListSelected() ||
       m_splitter->readOnlyListSelected())
    {
555 556 557 558 559
        action("file_save")->setEnabled(false);
        action("file_save_as")->setEnabled(false);
        action("renamePlaylist")->setEnabled(false);
        action("reloadPlaylist")->setEnabled(false);
        action("deleteItemPlaylist")->setEnabled(false);
560 561
    }
    else {
562 563 564 565
        action("file_save")->setEnabled(true);
        action("file_save_as")->setEnabled(true);
        action("renamePlaylist")->setEnabled(true);
        action("deleteItemPlaylist")->setEnabled(true);
566 567

	if(m_splitter->fileBasedListSelected() || m_splitter->dynamicListSelected())
568
	    action("reloadPlaylist")->setEnabled(true);
569
	else
570
	    action("reloadPlaylist")->setEnabled(false);
571
    }
572
    if(m_splitter->hasListSelected())
573
        action("duplicatePlaylist")->setEnabled(true);
574
    else
575
        action("duplicatePlaylist")->setEnabled(false);
576

577 578 579
    updatePlaylistInfo();
}

580 581 582 583 584
void JuK::slotQuit()
{
    kapp->quit();
}

585 586 587 588
////////////////////////////////////////////////////////////////////////////////
// settings menu
////////////////////////////////////////////////////////////////////////////////

589
void JuK::slotToggleSystemTray(bool enabled)
590
{
591
    if(enabled && !m_systemTray)
592
	setupSystemTray();
593 594 595
    else if(!enabled && m_systemTray) {
	delete m_systemTray;
	m_systemTray = 0;
596
	m_toggleDockOnCloseAction->setEnabled(false);
597
	m_togglePopupsAction->setEnabled(false);
598 599 600
    }
}

601 602
void JuK::slotEditKeys()
{
603
    KeyDialog::configure(m_accel, actions(), this);
604 605
}

606
////////////////////////////////////////////////////////////////////////////////
607
// additional player slots
608 609
////////////////////////////////////////////////////////////////////////////////

610
void JuK::slotPlayCurrent()
611
{
612 613
    m_player->stop();
    action("play")->activate();
614 615
}

616 617
void JuK::slotConfigureTagGuesser()
{
618
    TagGuesserConfigDlg(this).exec();
619 620
}

621 622
void JuK::slotConfigureFileRenamer()
{
623
    FileRenamerConfigDlg(this).exec();
624 625
}

626
#include "juk.moc"