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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

502 503 504 505
    hide();
    delete m_systemTray;
    m_systemTray = 0;

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

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

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

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

    s += m_splitter->playingTrack().simplifyWhiteSpace();
540 541 542 543

    return s;
}

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

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

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

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

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

570 571 572
    return action;
}

573 574 575 576
////////////////////////////////////////////////////////////////////////////////
// private slot definitions
////////////////////////////////////////////////////////////////////////////////

577
void JuK::slotPlaylistChanged()
578
{
579 580 581 582
    if(m_splitter->collectionListSelected() ||
       !m_splitter->hasListSelected() ||
       m_splitter->readOnlyListSelected())
    {
583 584 585 586 587
        action("file_save")->setEnabled(false);
        action("file_save_as")->setEnabled(false);
        action("renamePlaylist")->setEnabled(false);
        action("reloadPlaylist")->setEnabled(false);
        action("deleteItemPlaylist")->setEnabled(false);
588 589
    }
    else {
590 591 592 593
        action("file_save")->setEnabled(true);
        action("file_save_as")->setEnabled(true);
        action("renamePlaylist")->setEnabled(true);
        action("deleteItemPlaylist")->setEnabled(true);
594 595

	if(m_splitter->fileBasedListSelected() || m_splitter->dynamicListSelected())
596
	    action("reloadPlaylist")->setEnabled(true);
597
	else
598
	    action("reloadPlaylist")->setEnabled(false);
599
    }
600
    if(m_splitter->hasListSelected())
601
        action("duplicatePlaylist")->setEnabled(true);
602
    else
603
        action("duplicatePlaylist")->setEnabled(false);
604

605 606 607
    updatePlaylistInfo();
}

608 609 610 611 612
void JuK::slotQuit()
{
    kapp->quit();
}

613 614 615 616
////////////////////////////////////////////////////////////////////////////////
// settings menu
////////////////////////////////////////////////////////////////////////////////

617
void JuK::slotToggleSystemTray(bool enabled)
618
{
619
    if(enabled && !m_systemTray)
620
	setupSystemTray();
621 622 623
    else if(!enabled && m_systemTray) {
	delete m_systemTray;
	m_systemTray = 0;
624
	m_toggleDockOnCloseAction->setEnabled(false);
625
	m_togglePopupsAction->setEnabled(false);
626 627 628
    }
}

629 630
void JuK::slotEditKeys()
{
631
    KeyDialog::configure(m_accel, actions(), this);
632 633
}

634
////////////////////////////////////////////////////////////////////////////////
635
// additional player slots
636 637
////////////////////////////////////////////////////////////////////////////////

638
void JuK::slotPlayCurrent()
639
{
640 641
    m_player->stop();
    action("play")->activate();
642 643
}

644 645
void JuK::slotConfigureTagGuesser()
{
646
    TagGuesserConfigDlg(this).exec();
647 648
}

649 650
void JuK::slotConfigureFileRenamer()
{
651
    FileRenamerConfigDlg(this).exec();
652 653
}

654
#include "juk.moc"