juk.cpp 22.3 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

35 36
using namespace ActionCollection;

37 38 39 40
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////

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

48
    readSettings();
49

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

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

64 65
    m_player->setPlaylistInterface(m_splitter);

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

JuK::~JuK()
{
72

73 74
}

75 76 77 78 79
KActionCollection *JuK::actionCollection() const
{
    return ActionCollection::actions();
}

80 81 82 83
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////

84
void JuK::slotGuessTagInfoFromFile()
85
{
86 87 88 89 90 91
    m_splitter->slotGuessTagInfo(TagGuesser::FileName);
}

void JuK::slotGuessTagInfoFromInternet()
{
    m_splitter->slotGuessTagInfo(TagGuesser::MusicBrainz);
92 93
}

94 95 96 97 98 99 100 101 102 103
void JuK::back(int howMany)
{
    for(--howMany; howMany > 0; --howMany)
        m_splitter->playPreviousFile(m_randomPlayAction->isChecked());

    play(m_splitter->playPreviousFile(m_randomPlayAction->isChecked()));
}

void JuK::slotPopulateBackMenu()
{
Scott Wheeler's avatar
Scott Wheeler committed
104 105
    m_splitter->populatePlayHistoryMenu(m_backAction->popupMenu(),
					m_randomPlayAction->isChecked());
106 107 108 109 110 111 112
}

void JuK::openFile(const QString &file)
{
    m_splitter->open(file);
}

113 114 115 116 117 118
void JuK::openFile(const QStringList &files)
{
    for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
	openFile(*it);
}

119 120 121 122
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////

123 124
void JuK::setupLayout()
{
125
    m_splitter = new PlaylistSplitter(this, "playlistSplitter");
126
    setCentralWidget(m_splitter);
127 128

    // playlist item activation connection
Scott Wheeler's avatar
Scott Wheeler committed
129
    connect(m_splitter, SIGNAL(signalActivated()),
130
	    this, SLOT(slotPlayCurrent()));
Scott Wheeler's avatar
Scott Wheeler committed
131
    connect(m_splitter, SIGNAL(signalListBoxDoubleClicked()),
132
	    this, SLOT(slotPlayCurrent()));
133

134
    // create status bar
135

136
    m_statusLabel = new StatusLabel(statusBar());
137

138
    statusBar()->addWidget(m_statusLabel, 1);
139

Scott Wheeler's avatar
Scott Wheeler committed
140 141
    connect(m_splitter, SIGNAL(signalSelectedPlaylistCountChanged(int)),
	    m_statusLabel, SLOT(setPlaylistCount(int)));
142 143
    connect(m_splitter, SIGNAL(signalSelectedPlaylistTimeChanged(int)),
	    m_statusLabel, SLOT(setPlaylistTime(int)));
Scott Wheeler's avatar
Scott Wheeler committed
144 145
    connect(m_statusLabel, SIGNAL(jumpButtonClicked()),
	    m_splitter, SLOT(slotSelectPlaying()));
146

147 148
    PlayerManager::instance()->setStatusLabel(m_statusLabel);

149 150
    // Needs to be here because m_splitter is not called before setupActions
    // (because PlaylistSplitter itself accesses the actionCollection)
151

152
    new KAction(i18n("&Rename File"), 0, "CTRL+r", m_splitter, SLOT(slotRenameFile()),
153
                actions(), "renameFile"); // 4
154

155
    m_splitter->setFocus();
156

157
    resize(750, 500);
158 159
}

160 161
void JuK::setupActions()
{
162
    //////////////////////////////////////////////////
163
    // file menu
164
    //////////////////////////////////////////////////
165

Scott Wheeler's avatar
Scott Wheeler committed
166
    KActionMenu *newMenu = new KActionMenu(i18n("&New"), "filenew",
167
					   actions(), "file_new");
Scott Wheeler's avatar
Scott Wheeler committed
168

169 170 171 172 173 174
    // 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
175 176 177
    newMenu->insert(createSplitterAction(i18n("Empty Playlist..."),
					 SLOT(slotCreatePlaylist()), 0, 0, 0));

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

181 182 183 184 185 186 187 188
    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");
189

190
    KStdAction::quit(this, SLOT(slotQuit()), actions());
191

192
    //////////////////////////////////////////////////
193
    // edit menu
194 195
    //////////////////////////////////////////////////

196 197 198 199
    KStdAction::cut(kapp,   SLOT(cut()),   actions());
    KStdAction::copy(kapp,  SLOT(copy()),  actions());
    KStdAction::paste(kapp, SLOT(paste()), actions());
    KStdAction::clear(kapp, SLOT(clear()), actions());
200

201
    KStdAction::selectAll(kapp, SLOT(selectAll()), actions());
202

203
    createSplitterAction(
204
	i18n("Advanced Search"), SLOT(slotAdvancedSearch()), "advancedSearch", "find", "s");
205

206
    //////////////////////////////////////////////////
207
    // view menu
208
    //////////////////////////////////////////////////
209

Scott Wheeler's avatar
Scott Wheeler committed
210
    m_showSearchAction = new KToggleAction(i18n("Show &Search Bar"), "filefind",
211
					   0, actions(), "showSearch");
Scott Wheeler's avatar
Scott Wheeler committed
212
    m_showEditorAction = new KToggleAction(i18n("Show &Tag Editor"), "edit",
213
					   0, actions(), "showEditor");
214
    m_showHistoryAction = new KToggleAction(i18n("Show &History"), "history",
215
					   0, actions(), "showHistory");
216

217
    createSplitterAction(i18n("Refresh Items"), SLOT(slotRefresh()), "refresh", "reload");
218

219
    //////////////////////////////////////////////////
220
    // play menu
221 222
    //////////////////////////////////////////////////

Scott Wheeler's avatar
Scott Wheeler committed
223
    m_randomPlayAction = new KToggleAction(i18n("&Random Play"), 0,
224
					   actions(), "randomPlay");
Scott Wheeler's avatar
Scott Wheeler committed
225

226 227 228
    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
229

230
    m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
231
					   this, SLOT(back()), actions(), "back");
232

Scott Wheeler's avatar
Scott Wheeler committed
233 234 235 236
    connect(m_backAction->popupMenu(), SIGNAL(aboutToShow()),
	    this, SLOT(slotPopulateBackMenu()));
    connect(m_backAction->popupMenu(), SIGNAL(activated(int)),
	    this, SLOT(back(int)));
237

238 239 240 241
    new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
    new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist");

    // the following are not visible by default
242

243 244 245 246 247 248 249
    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");
    
250

251
    //////////////////////////////////////////////////
252
    // tagger menu
253 254
    //////////////////////////////////////////////////

255
    createSplitterAction(i18n("&Save"), SLOT(slotSaveTag()),
Scott Wheeler's avatar
Scott Wheeler committed
256 257 258
			 "saveItem",   "filesave", "CTRL+t");
    createSplitterAction(i18n("&Delete"), SLOT(slotDeleteSelectedItems()),
			 "removeItem", "editdelete");
259

260 261
    KActionMenu *guessMenu = new KActionMenu(i18n("&Guess Tag Information"),
					     QString::null, actions(),
Scott Wheeler's avatar
Scott Wheeler committed
262
					     "guessTag");
263

264 265 266
    guessMenu->insert(
	new KAction(i18n("From &Filename"), 0, "CTRL+f", this, SLOT(slotGuessTagInfoFromFile()),
		    actions(), "guessTagFile"));
267
#if HAVE_MUSICBRAINZ
268 269 270
    guessMenu->insert(
	new KAction(i18n("From &Internet"), 0, "CTRL+i", this, SLOT(slotGuessTagInfoFromInternet()),
		    actions(), "guessTagInternet"));
271
#endif
Scott Wheeler's avatar
Scott Wheeler committed
272

273
    //////////////////////////////////////////////////
274
    // settings menu
275 276
    //////////////////////////////////////////////////

277
    setStandardToolBarMenuEnabled(true);
278

Stephan Binner's avatar
Stephan Binner committed
279
    m_toggleSplashAction = new KToggleAction(i18n("Show Splash Screen on Startup"),
280
					     0, actions(), "showSplashScreen");
Scott Wheeler's avatar
Scott Wheeler committed
281 282

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

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

288
    m_togglePopupsAction = new KToggleAction(i18n("Popup &Track Announcement"),
289
					     0, this, 0, actions(), "togglePopups");
290

Scott Wheeler's avatar
Scott Wheeler committed
291 292
    connect(m_toggleSystemTrayAction, SIGNAL(toggled(bool)),
	    this, SLOT(slotToggleSystemTray(bool)));
293

Scott Wheeler's avatar
Scott Wheeler committed
294

295
    m_outputSelectAction = Player::playerSelectAction(actions());
296

297
    if(m_outputSelectAction)
298
        m_outputSelectAction->setCurrentItem(0);
299

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

303
    new KAction(i18n("&File Renamer..."), 0, 0, this, SLOT(slotConfigureFileRenamer()),
304
		actions(), "fileRenamerConfig");
305

306
    KStdAction::keyBindings(this, SLOT(slotEditKeys()), actions());
307

308
    //////////////////////////////////////////////////
309
    // just in the toolbar
310 311
    //////////////////////////////////////////////////

312
    m_sliderAction = new SliderAction(i18n("Track Position"), actions(),
Scott Wheeler's avatar
Scott Wheeler committed
313
				      "trackPositionAction");
314 315

    createGUI();
316 317

    // set the slider to the proper orientation and make it stay that way
318
    m_sliderAction->slotUpdateOrientation();
319 320
}

321 322 323 324 325 326
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
327 328 329 330
    connect(m_showSearchAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetSearchVisible(bool)));
    connect(m_showEditorAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetEditorVisible(bool)));
331 332
    connect(m_showHistoryAction, SIGNAL(toggled(bool)),
	    m_splitter, SLOT(slotSetHistoryVisible(bool)));
333
    connect(this, SIGNAL(dockWindowPositionChanged(QDockWindow *)),
Scott Wheeler's avatar
Scott Wheeler committed
334 335 336
	    m_sliderAction, SLOT(slotUpdateOrientation(QDockWindow *)));
    connect(m_splitter, SIGNAL(signalPlaylistChanged()),
	    this, SLOT(slotPlaylistChanged()));
337 338
}

339
void JuK::setupSystemTray()
340
{
341
    if(m_toggleSystemTrayAction && m_toggleSystemTrayAction->isChecked()) {
342 343
        m_systemTray = new SystemTray(this, "systemTray");
        m_systemTray->show();
344

345
        connect(this, SIGNAL(signalNewSong(const QString&)),
Scott Wheeler's avatar
Scott Wheeler committed
346
		m_systemTray, SLOT(slotNewSong(const QString&)));
347

348
        m_toggleDockOnCloseAction->setEnabled(true);
349
	m_togglePopupsAction->setEnabled(true);
350

351
        connect(m_systemTray, SIGNAL(quitSelected()), this, SLOT(slotQuit()));
352
    }
353
    else {
354 355
        m_systemTray = 0;
        m_toggleDockOnCloseAction->setEnabled(false);
356
	m_togglePopupsAction->setEnabled(false);
357
    }
358 359
}

360 361 362
void JuK::setupGlobalAccels()
{
    m_accel = new KGlobalAccel(this);
363

364 365 366 367 368 369 370 371 372
    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()));
373
    KeyDialog::insert(m_accel, "ShowHide",    i18n("Show / Hide"),  this,                  SLOT(slotShowHide()));
374

375 376 377 378 379
    m_accel->setConfigGroup("Shortcuts");
    m_accel->readSettings();
    m_accel->updateConnections();
}

380 381 382 383
void JuK::processArgs()
{
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    QStringList files;
384

385
    for(int i = 0; i < args->count(); i++)
386
        files.append(args->arg(i));
387

388
    m_splitter->open(files);
389 390
}

391 392 393
void JuK::keyPressEvent(QKeyEvent *e)
{
    if (e->key() >= Qt::Key_Back && e->key() <= Qt::Key_MediaLast)
394
        e->accept();
395 396 397
    KMainWindow::keyPressEvent(e);
}

398 399 400 401 402 403 404 405 406
/**
 * 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");
407
        m_showSplash = config->readBoolEntry("ShowSplashScreen", true);
408
        m_startDocked = config->readBoolEntry("StartDocked", false);
409 410 411
    }
}

412 413
void JuK::readConfig()
{
414
    // Automagically save and m_restore many window settings.
415 416
    setAutoSaveSettings();

417
    KConfig *config = KGlobal::config();
418
    { // player settings
419
        KConfigGroupSaver saver(config, "Player");
420 421
        if(m_sliderAction->volumeSlider()) {
	    int maxVolume = m_sliderAction->volumeSlider()->maxValue();
Scott Wheeler's avatar
Scott Wheeler committed
422
	    int volume = config->readNumEntry("Volume", maxVolume);
423
            m_sliderAction->volumeSlider()->setValue(volume);
424
        }
425 426
        bool randomPlay = config->readBoolEntry("RandomPlay", false);
        m_randomPlayAction->setChecked(randomPlay);
427

428
        bool loopPlaylist = config->readBoolEntry("LoopPlaylist", false);
429
        ActionCollection::action<KToggleAction>("loopPlaylist")->setChecked(loopPlaylist);
430
    }
431
    { // view settings
432
        KConfigGroupSaver saver(config, "View");
433 434 435 436 437

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

438 439 440
        bool showEditor = config->readBoolEntry("ShowEditor", false);
        m_showEditorAction->setChecked(showEditor);
        m_splitter->slotSetEditorVisible(showEditor);
441

442 443 444
	// 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.
445

446 447
	bool showHistory = config->readBoolEntry("ShowHistory", false);
	m_showHistoryAction->setChecked(showHistory);
448
    }
449 450
    { // general settings
        KConfigGroupSaver saver(config, "Settings");
451

452 453
        bool dockInSystemTray = config->readBoolEntry("DockInSystemTray", true);
        m_toggleSystemTrayAction->setChecked(dockInSystemTray);
454

455 456
        bool dockOnClose = config->readBoolEntry("DockOnClose", true);
        m_toggleDockOnCloseAction->setChecked(dockOnClose);
457

458 459
        bool showPopups = config->readBoolEntry("TrackPopup", false);
        m_togglePopupsAction->setChecked(showPopups);
460

461 462
        if(m_outputSelectAction)
            m_outputSelectAction->setCurrentItem(config->readNumEntry("MediaSystem", 0));
463
    }
464

465
    m_toggleSplashAction->setChecked(m_showSplash);
466 467 468 469
}

void JuK::saveConfig()
{
470
    KConfig *config = KGlobal::config();
471
    { // player settings
472
        KConfigGroupSaver saver(config, "Player");
473 474 475 476 477
	config->writeEntry("Volume", m_sliderAction->volumeSlider()->value());
	config->writeEntry("RandomPlay", m_randomPlayAction->isChecked());

	KToggleAction *a = ActionCollection::action<KToggleAction>("loopPlaylist");
	config->writeEntry("LoopPlaylist", a->isChecked());
478
    }
479 480
    { // view settings
        KConfigGroupSaver saver(config, "View");
481

482
        config->writeEntry("ShowEditor", m_showEditorAction->isChecked());
483
        config->writeEntry("ShowSearch", m_showSearchAction->isChecked());
484
	config->writeEntry("ShowHistory", m_showHistoryAction->isChecked());
485
    }
486 487
    { // general settings
        KConfigGroupSaver saver(config, "Settings");
488
        config->writeEntry("ShowSplashScreen", m_toggleSplashAction->isChecked());
489
        config->writeEntry("StartDocked", m_startDocked);
490 491 492 493 494
        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());
495
    }
496
    config->sync();
497 498
}

499
bool JuK::queryExit()
500
{
501 502
    m_startDocked = !isVisible();

503
    hide();
504
    action("stop")->activate();
505 506 507
    delete m_systemTray;
    m_systemTray = 0;

508
    Cache::instance()->save();
509
    saveConfig();
510
    delete m_splitter;
511
    return true;
512 513
}

514 515
bool JuK::queryClose()
{
516 517 518 519 520
    if(!m_shuttingDown &&
       !kapp->sessionSaving() &&
       m_systemTray &&
       m_toggleDockOnCloseAction->isChecked())
    {
521
	KMessageBox::information(this,
Scott Wheeler's avatar
Scott Wheeler committed
522 523 524
	    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");
525 526 527 528 529 530 531
	hide();
	return false;
    }
    else
	return true;
}

532 533 534
QString JuK::playingString() const
{
    QString s;
535 536
    if(!m_player->playing() && !m_player->paused())
	return i18n("No song playing");
537

538 539 540 541
    if(!m_splitter->playingArtist().isEmpty())
	s = m_splitter->playingArtist().simplifyWhiteSpace() + " - ";

    s += m_splitter->playingTrack().simplifyWhiteSpace();
542 543 544 545

    return s;
}

546 547
void JuK::updatePlaylistInfo()
{
Scott Wheeler's avatar
Scott Wheeler committed
548
    m_statusLabel->setPlaylistInfo(m_splitter->visiblePlaylistName(),
549 550
				   m_splitter->selectedPlaylistCount(),
				   m_splitter->selectedPlaylistTotalTime());
551 552 553 554
}

void JuK::play(const QString &file)
{
555
    m_player->play(file);
556
    emit signalNewSong(playingString());
557 558
}

Scott Wheeler's avatar
Scott Wheeler committed
559 560 561
KAction *JuK::createSplitterAction(const QString &text, const char *slot,
				   const char *name, const QString &pix,
				   const KShortcut &shortcut)
562 563 564 565
{
    KAction *action;

    if(pix.isNull())
566
	action = new KAction(text, shortcut, actions(), name);
567
    else
568
	action = new KAction(text, pix, shortcut, actions(), name);
569 570

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

572 573 574
    return action;
}

575 576 577 578
////////////////////////////////////////////////////////////////////////////////
// private slot definitions
////////////////////////////////////////////////////////////////////////////////

579 580 581 582 583
void JuK::slotShowHide()
{
    setShown(!isShown());
}

584
void JuK::slotPlaylistChanged()
585
{
586 587 588 589
    if(m_splitter->collectionListSelected() ||
       !m_splitter->hasListSelected() ||
       m_splitter->readOnlyListSelected())
    {
590 591 592 593 594
        action("file_save")->setEnabled(false);
        action("file_save_as")->setEnabled(false);
        action("renamePlaylist")->setEnabled(false);
        action("reloadPlaylist")->setEnabled(false);
        action("deleteItemPlaylist")->setEnabled(false);
595 596
    }
    else {
597 598 599 600
        action("file_save")->setEnabled(true);
        action("file_save_as")->setEnabled(true);
        action("renamePlaylist")->setEnabled(true);
        action("deleteItemPlaylist")->setEnabled(true);
601 602

	if(m_splitter->fileBasedListSelected() || m_splitter->dynamicListSelected())
603
	    action("reloadPlaylist")->setEnabled(true);
604
	else
605
	    action("reloadPlaylist")->setEnabled(false);
606
    }
607
    if(m_splitter->hasListSelected())
608
        action("duplicatePlaylist")->setEnabled(true);
609
    else
610
        action("duplicatePlaylist")->setEnabled(false);
611

612 613 614
    updatePlaylistInfo();
}

615 616 617 618 619
void JuK::slotQuit()
{
    kapp->quit();
}

620 621 622 623
////////////////////////////////////////////////////////////////////////////////
// settings menu
////////////////////////////////////////////////////////////////////////////////

624
void JuK::slotToggleSystemTray(bool enabled)
625
{
626
    if(enabled && !m_systemTray)
627
	setupSystemTray();
628 629 630
    else if(!enabled && m_systemTray) {
	delete m_systemTray;
	m_systemTray = 0;
631
	m_toggleDockOnCloseAction->setEnabled(false);
632
	m_togglePopupsAction->setEnabled(false);
633 634 635
    }
}

636 637
void JuK::slotEditKeys()
{
638
    KeyDialog::configure(m_accel, actions(), this);
639 640
}

641
////////////////////////////////////////////////////////////////////////////////
642
// additional player slots
643 644
////////////////////////////////////////////////////////////////////////////////

645
void JuK::slotPlayCurrent()
646
{
647 648
    m_player->stop();
    action("play")->activate();
649 650
}

651 652
void JuK::slotConfigureTagGuesser()
{
653
    TagGuesserConfigDlg(this).exec();
654 655
}

656 657
void JuK::slotConfigureFileRenamer()
{
658
    FileRenamerConfigDlg(this).exec();
659 660
}

661
#include "juk.moc"