Пример #1
0
// TODO convert to use xmlui file
void KuickShow::initGUI( const KURL& startDir )
{
	KURL startURL( startDir );
	if ( !KProtocolInfo::supportsListing( startURL ) )
		startURL = KURL();

    fileWidget = new FileWidget( startURL, this, "MainWidget" );
    setFocusProxy( fileWidget );

    KActionCollection *coll = fileWidget->actionCollection();

    redirectDeleteAndTrashActions(coll);

    connect( fileWidget, SIGNAL( fileSelected( const KFileItem * ) ),
             this, SLOT( slotSelected( const KFileItem * ) ));

    connect( fileWidget, SIGNAL( fileHighlighted( const KFileItem * )),
             this, SLOT( slotHighlighted( const KFileItem * ) ));

    connect( fileWidget, SIGNAL( urlEntered( const KURL&  )),
             this, SLOT( dirSelected( const KURL& )) );


    fileWidget->setAcceptDrops(true);
    connect( fileWidget, SIGNAL( dropped( const KFileItem *, QDropEvent *, const KURL::List & )),
             this, SLOT( slotDropped( const KFileItem *, QDropEvent *, const KURL::List &)) );

    // setup actions
    KAction *open = KStdAction::open( this, SLOT( slotOpenURL() ),
                                      coll, "openURL" );

    KAction *print = KStdAction::print( this, SLOT( slotPrint() ),
                                        coll, "kuick_print" );
    print->setText( i18n("Print Image...") );

    KAction *configure = new KAction( i18n("Configure %1...").arg( KGlobal::instance()->aboutData()->programName() ), "configure",
                                      KShortcut(),
                                      this, SLOT( configuration() ),
                                      coll, "kuick_configure" );
    KAction *slide = new KAction( i18n("Start Slideshow" ), "ksslide",
                                  KShortcut( Key_F2 ),
                                  this, SLOT( startSlideShow() ),
                                  coll, "kuick_slideshow" );
    KAction *about = new KAction( i18n( "About KuickShow" ), "about",
                                  KShortcut(),
                                  this, SLOT( about() ), coll, "about" );

    oneWindowAction = new KToggleAction( i18n("Open Only One Image Window"),
                                         "window_new",
                                         KShortcut( CTRL+Key_N ), coll,
                                         "kuick_one window" );

    m_toggleBrowserAction = new KToggleAction( i18n("Show File Browser"), KShortcut( Key_Space ), coll, "toggleBrowser" );
    m_toggleBrowserAction->setCheckedState(i18n("Hide File Browser"));
    connect( m_toggleBrowserAction, SIGNAL( toggled( bool ) ),
             SLOT( toggleBrowser() ));

    KAction *showInOther = new KAction( i18n("Show Image"), KShortcut(),
                                        this, SLOT( slotShowInOtherWindow() ),
                                        coll, "kuick_showInOtherWindow" );
    KAction *showInSame = new KAction( i18n("Show Image in Active Window"),
                                       KShortcut(),
                                       this, SLOT( slotShowInSameWindow() ),
                                       coll, "kuick_showInSameWindow" );
    KAction *showFullscreen = new KAction( i18n("Show Image in Fullscreen Mode"),
					   KShortcut(), this, SLOT( slotShowFullscreen() ),
					   coll, "kuick_showFullscreen" );

    KAction *quit = KStdAction::quit( this, SLOT(slotQuit()), coll, "quit");

    // remove QString::null parameter -- ellis
    coll->readShortcutSettings( QString::null );
    m_accel = coll->accel();

    // menubar
    KMenuBar *mBar = menuBar();
    QPopupMenu *fileMenu = new QPopupMenu( mBar, "file" );
    open->plug( fileMenu );
    showInOther->plug( fileMenu );
    showInSame->plug( fileMenu );
    showFullscreen->plug( fileMenu );
    fileMenu->insertSeparator();
    slide->plug( fileMenu );
    print->plug( fileMenu );
    fileMenu->insertSeparator();
    quit->plug( fileMenu );

    QPopupMenu *editMenu = new QPopupMenu( mBar, "edit" );
    coll->action("mkdir")->plug( editMenu );
    coll->action("delete")->plug( editMenu );
    editMenu->insertSeparator();
    coll->action("properties")->plug( editMenu );


    // remove the Sorting submenu (and the separator below)
    // from the main contextmenu
    KActionMenu *sortingMenu = static_cast<KActionMenu*>( coll->action("sorting menu"));
    KActionMenu *mainActionMenu = static_cast<KActionMenu*>( coll->action("popupMenu"));
    QPopupMenu *mainPopup = mainActionMenu->popupMenu();
    int sortingIndex = mainPopup->indexOf( sortingMenu->itemId( 0 ) );
    int separatorId = mainPopup->idAt( sortingIndex + 1 );
    QMenuItem *separatorItem = mainPopup->findItem( separatorId );
    if ( separatorItem && separatorItem->isSeparator() )
        mainPopup->removeItem( separatorId );
    mainActionMenu->remove( sortingMenu );

    // add the sorting menu and a separator into the View menu
    KActionMenu *viewActionMenu = static_cast<KActionMenu*>( coll->action("view menu"));
    viewActionMenu->popupMenu()->insertSeparator( 0 );
    sortingMenu->plug( viewActionMenu->popupMenu(), 0 ); // on top of the menu


    QPopupMenu *settingsMenu = new QPopupMenu( mBar, "settings" );
    configure->plug( settingsMenu );

    mBar->insertItem( i18n("&File"), fileMenu );
    mBar->insertItem( i18n("&Edit"), editMenu );
    viewActionMenu->plug( mBar );
    mBar->insertItem( i18n("&Settings"), settingsMenu );

    // toolbar
    KToolBar *tBar = toolBar();
    tBar->setText( i18n( "Main Toolbar" ) );

    coll->action("up")->plug( tBar );
    coll->action("back")->plug( tBar );
    coll->action("forward")->plug( tBar );
    coll->action("home")->plug( tBar );
    coll->action("reload")->plug( tBar );

    tBar->insertSeparator();

    coll->action( "short view" )->plug( tBar );
    coll->action( "detailed view" )->plug( tBar );
    coll->action( "preview")->plug( tBar );

    tBar->insertSeparator();
    configure->plug( tBar );
    slide->plug( tBar );
    tBar->insertSeparator();
    oneWindowAction->plug( tBar );
    print->plug( tBar );
    tBar->insertSeparator();
    about->plug( tBar );

    QPopupMenu *help = helpMenu( QString::null, false );
    mBar->insertItem( KStdGuiItem::help().text() , help );


    KStatusBar* sBar = statusBar();
    sBar->insertItem( "           ", URL_ITEM, 10 );
    sBar->insertItem( "                          ", META_ITEM, 2 );
    sBar->setItemAlignment(URL_ITEM, QLabel::AlignVCenter | QLabel::AlignLeft);

    fileWidget->setFocus();

    KConfig *kc = KGlobal::config();
    kc->setGroup("SessionSettings");
    bool oneWindow = kc->readBoolEntry("OpenImagesInActiveWindow", true );
    oneWindowAction->setChecked( oneWindow );

    tBar->show();

    // Address box in address tool bar
    KToolBar *addressToolBar = toolBar( "address_bar" );
    const int ID_ADDRESSBAR = 1;

    cmbPath = new KURLComboBox( KURLComboBox::Directories,
                                true, addressToolBar, "address_combo_box" );
    KURLCompletion *cmpl = new KURLCompletion( KURLCompletion::DirCompletion );
    cmbPath->setCompletionObject( cmpl );
    cmbPath->setAutoDeleteCompletionObject( true );

    addressToolBar->insertWidget( ID_ADDRESSBAR, 1, cmbPath);
    addressToolBar->setItemAutoSized( ID_ADDRESSBAR );

    connect( cmbPath, SIGNAL( urlActivated( const KURL& )),
             this, SLOT( slotSetURL( const KURL& )));
    connect( cmbPath, SIGNAL( returnPressed()),
             this, SLOT( slotURLComboReturnPressed()));


    fileWidget->initActions();
    fileWidget->clearHistory();
    dirSelected( fileWidget->url() );

    setCentralWidget( fileWidget );
    setupGUI( KMainWindow::Save );

    coll->action( "reload" )->setShortcut( KStdAccel::reload() );
    coll->action( "short view" )->setShortcut(Key_F6);
    coll->action( "detailed view" )->setShortcut(Key_F7);
    coll->action( "show hidden" )->setShortcut(Key_F8);
    coll->action( "mkdir" )->setShortcut(Key_F10);
    coll->action( "preview" )->setShortcut(Key_F11);
    coll->action( "separate dirs" )->setShortcut(Key_F12);
}
Пример #2
0
Player::Player(QWidget *parent) : KXmlGuiWindow(parent) {
	//SETUP DATABASE
	QDir(KGlobal::dirs()->saveLocation("data")).mkdir("projekt7"); //NOTE: creates the projekt7 directory if it doesn't already exist
	QString db_path = KGlobal::dirs()->saveLocation("data") + "projekt7/tracks_db";
	int return_code = sqlite3_open(qtos(db_path), &tracks_db);
	if (return_code) {
		showError("Failed to open the Projekt7 Track Database: ", sqlite3_errmsg(tracks_db));
		exit(return_code);
	}
	const char *create_table = "CREATE TABLE IF NOT EXISTS `tracks` (`tid` INTEGER PRIMARY KEY, `artist` VARCHAR KEY ASC, `year` INT KEY ASC, `album` VARCHAR, `track_number` INT KEY ASC, `title` VARCHAR, `path` VARCHAR, `length` INT, `playcount` INT)"; //TODO make use of the `length` and `playcount` columns
	char *errmsg;
	return_code = sqlite3_exec(tracks_db, create_table, 0, 0, &errmsg);
	if (return_code) {
		showError("Failed to create `tracks` table: ", errmsg);
		sqlite3_free(errmsg);
		exit(return_code);
	}
	updateNumTracks();
	
	//SETUP PHONON
	now_playing = new Phonon::MediaObject(this);
	Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
	createPath(now_playing, audioOutput);
	now_playing->setTickInterval(1000);
	
	//SETUP WIDGETS
	QWidget *central_widget = new QWidget(this);
	KToolBar *toolbar_widget = new KToolBar(i18n("Main Toolbar"), central_widget);
	toolbar_widget->setIconDimensions(32);
	playlist_widget = new QWidget(central_widget);
	artist_list = new KListWidget(playlist_widget);
	artist_list->addItem(ALL);
	album_list = new KListWidget(playlist_widget);
	titles_list = new KListWidget(playlist_widget);
	QAction* tb_previousAction = toolbar_widget->addAction(KIcon("media-skip-backward"), "");
	QString previousHelpText = i18n("Play the previous track");
	tb_previousAction->setToolTip(previousHelpText);
	QAction* tb_pauseAction = toolbar_widget->addAction(KIcon("media-playback-pause"), "");
	QString plauseHelpText = i18n("Plause playback");
	tb_pauseAction->setToolTip(plauseHelpText);
	QAction* tb_playAction = toolbar_widget->addAction(KIcon("media-playback-start"), "");
	QString playHelpText = i18n("Play the track");
	tb_playAction->setToolTip(playHelpText);
	QAction* tb_nextAction = toolbar_widget->addAction(KIcon("media-skip-forward"), "");
	QString nextHelpText = i18n("Play the next track");
	tb_nextAction->setToolTip(nextHelpText);
	toolbar_widget->addSeparator();
	Phonon::VolumeSlider *volumeSlider = new Phonon::VolumeSlider;
	volumeSlider->setAudioOutput(audioOutput);
	volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
	toolbar_widget->addWidget(volumeSlider);
	toolbar_widget->addSeparator();
	Phonon::SeekSlider *seekSlider = new Phonon::SeekSlider(now_playing);
	volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
	toolbar_widget->addWidget(seekSlider);
	toolbar_widget->addSeparator();
	cur_time = new QLabel(" 0:00", toolbar_widget);
	cur_time->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
	toolbar_widget->addWidget(cur_time);
	toolbar_widget->addWidget(new QLabel(" / ", toolbar_widget));
	track_duration = new QLabel("0:00", toolbar_widget);
	track_duration->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
	toolbar_widget->addWidget(track_duration);
	queued = new KIcon("go-next-view");
	
	QHBoxLayout *listLayout = new QHBoxLayout;
	listLayout->addWidget(artist_list);
	listLayout->addWidget(album_list);
	listLayout->addWidget(titles_list);
	playlist_widget->setLayout(listLayout);
	
	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(toolbar_widget);
	mainLayout->addWidget(playlist_widget);
	central_widget->setLayout(mainLayout);
	
	setCentralWidget(central_widget);
	
	//SETUP STATUS BAR
	KStatusBar* bar = statusBar();
	bar->insertPermanentItem("", SONG_NAME, true);
	bar->setItemAlignment(SONG_NAME, Qt::AlignLeft | Qt::AlignVCenter);
	
	//SETUP SYSTEM TRAY ICON
	tray_icon = new KSystemTrayIcon("projekt7", this);
	tray_icon->show();
	
	//SETUP METADATA WINDOW
	metadata_window = new QWidget(this, Qt::Dialog);
	metadata_window->setWindowModality(Qt::WindowModal);
	metadata_window->setWindowTitle("Track Details  |  Projekt 7");
	mw_ok_button = new KPushButton(KIcon("dialog-ok-apply"), "OK", metadata_window);
	mw_ok_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
	
	QGridLayout *mwLayout = new QGridLayout;
	mwLayout->addWidget(new QLabel("Artist:",        metadata_window), 0, 0);
	mwLayout->addWidget(new QLabel("Year:",          metadata_window), 1, 0);
	mwLayout->addWidget(new QLabel("Album:",         metadata_window), 2, 0);
	mwLayout->addWidget(new QLabel("Track Number:",  metadata_window), 3, 0);
	mwLayout->addWidget(new QLabel("Title:",         metadata_window), 4, 0);
	mwLayout->addWidget(new QLabel("File Path:",     metadata_window), 5, 0);
	mwLayout->addWidget(mw_artist       = new QLabel(metadata_window), 0, 1);
	mwLayout->addWidget(mw_year         = new QLabel(metadata_window), 1, 1);
	mwLayout->addWidget(mw_album        = new QLabel(metadata_window), 2, 1);
	mwLayout->addWidget(mw_track_number = new QLabel(metadata_window), 3, 1);
	mwLayout->addWidget(mw_title        = new QLabel(metadata_window), 4, 1);
	mwLayout->addWidget(mw_path         = new QLabel(metadata_window), 5, 1);
	mwLayout->addWidget(mw_ok_button, 6, 0, 1, 2, Qt::AlignCenter);
	metadata_window->setLayout(mwLayout);
	
	//SETUP QUEUE EDITOR WINDOW
	queue_window = new QWidget(this, Qt::Dialog);
	queue_window->setWindowModality(Qt::WindowModal);
	queue_window->setWindowTitle("Track Queue Editor  |  Projekt 7");
	qw_ok_button = new KPushButton(KIcon("dialog-ok-apply"), "OK", queue_window);
	qw_ok_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
	
	QVBoxLayout *qw_buttons_layout = new QVBoxLayout;
	KPushButton *qw_top_button     = new KPushButton(KIcon("go-top"),      "", queue_window);
	KPushButton *qw_up_button      = new KPushButton(KIcon("go-up"),       "", queue_window);
	KPushButton *qw_down_button    = new KPushButton(KIcon("go-down"),     "", queue_window);
	KPushButton *qw_bottom_button  = new KPushButton(KIcon("go-bottom"),   "", queue_window);
	KPushButton *qw_remove_button  = new KPushButton(KIcon("edit-delete"), "", queue_window);
	qw_buttons_layout->addWidget(qw_top_button);
	qw_buttons_layout->addWidget(qw_up_button);
	qw_buttons_layout->addWidget(qw_down_button);
	qw_buttons_layout->addWidget(qw_bottom_button);
	qw_buttons_layout->addWidget(qw_remove_button);
	
	QHBoxLayout *qw_list_buttons_layout = new QHBoxLayout;
	qw_queue_list = new KListWidget(queue_window);
	QWidget *qw_button_holder = new QWidget(queue_window);
	qw_button_holder->setLayout(qw_buttons_layout);
	qw_list_buttons_layout->addWidget(qw_queue_list);
	qw_list_buttons_layout->addWidget(qw_button_holder);
	
	QVBoxLayout *qwLayout = new QVBoxLayout;
	QWidget *qw_list_buttons = new QWidget(queue_window);
	qw_list_buttons->setLayout(qw_list_buttons_layout);
	qwLayout->addWidget(qw_list_buttons);
	qwLayout->addWidget(qw_ok_button, 0, Qt::AlignCenter);
	queue_window->setLayout(qwLayout);
	
	//SETUP ACTIONS
 	KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
	connect(kapp, SIGNAL(aboutToQuit()), this, SLOT(quit()));
	connect(now_playing, SIGNAL(aboutToFinish()), this, SLOT(enqueueNext()));
	connect(now_playing, SIGNAL(totalTimeChanged(qint64)), this, SLOT(updateDuration(qint64)));
	connect(now_playing, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
	KAction *openFilesAction = setupKAction("document-open", i18n("Open"), i18n("Load the selected files"), "files");
	openFilesAction->setShortcut(QKeySequence::Open);
	connect(openFilesAction, SIGNAL(triggered(bool)), this, SLOT(loadFiles()));
	KAction *openDirectoryAction = setupKAction("document-open-folder", i18n("Open Directory..."), i18n("Load all files in the selected directory and its subdirectories"), "directory");
	openDirectoryAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
	connect(openDirectoryAction, SIGNAL(triggered(bool)), this, SLOT(loadDirectory()));
	KAction *previousAction = setupKAction("media-skip-backward", i18n("Previous"), previousHelpText, "previous");
	previousAction->setShortcut(QKeySequence(Qt::Key_Z));
	connect(previousAction, SIGNAL(triggered(bool)), this, SLOT(previous()));
	connect(tb_previousAction, SIGNAL(triggered(bool)), this, SLOT(previous()));
	KAction *pauseAction = setupKAction("media-playback-pause", i18n("Pause"), plauseHelpText, "pause");
	pauseAction->setShortcut(QKeySequence(Qt::Key_C));
	connect(pauseAction, SIGNAL(triggered(bool)), this, SLOT(pause()));
	connect(tb_pauseAction, SIGNAL(triggered(bool)), this, SLOT(pause()));
	KAction *playAction = setupKAction("media-playback-start", i18n("Play"), playHelpText, "play");
	playAction->setShortcut(QKeySequence(Qt::Key_X));
	connect(playAction, SIGNAL(triggered(bool)), this, SLOT(play()));
	connect(tb_playAction, SIGNAL(triggered(bool)), this, SLOT(play()));
	KAction *nextAction = setupKAction("media-skip-forward", i18n("Next"), nextHelpText, "next");
	nextAction->setShortcut(QKeySequence(Qt::Key_V));
	connect(nextAction, SIGNAL(triggered(bool)), this, SLOT(next()));
	connect(tb_nextAction, SIGNAL(triggered(bool)), this, SLOT(next()));
	KAction *queueAction = setupKAction("go-next-view", i18n("Queue Track"), "Enqueue the current track", "queue");
	queueAction->setShortcut(QKeySequence(Qt::Key_Q));
	connect(queueAction, SIGNAL(triggered(bool)), this, SLOT(queue()));
	shuffleAction = setupKAction("media-playlist-shuffle", i18n("Suffle"), "The next track will be random when checked", "shuffle");
	shuffleAction->setCheckable(true);
	connect(shuffleAction, SIGNAL(triggered(bool)), this, SLOT(shuffle(bool)));
	KAction *viewCurrentTrackAction = setupKAction("go-last", i18n("Current Track"), i18n("Show the Current Track in the Playlist"), "current_track");
	connect(viewCurrentTrackAction, SIGNAL(triggered(bool)), this, SLOT(viewCurrentTrack()));
	KAction *viewTrackDetailsAction = setupKAction("view-media-lyrics", i18n("Track Details"), i18n("View the playing track's metadata"), "track_details");
	connect(viewTrackDetailsAction, SIGNAL(triggered(bool)), this, SLOT(viewTrackDetails()));
	KAction *viewTrackQueueAction = setupKAction("view-time-schedule-edit", i18n("Track Queue"), i18n("Edit the track queue"), "track_queue");
	connect(viewTrackQueueAction, SIGNAL(triggered(bool)), this, SLOT(viewTrackQueue()));
	viewPlaylistAction = setupKAction("view-file-columns", i18n("Playlist"), i18n("Show/Hide the playlist"), "playlist");
	viewPlaylistAction->setCheckable(true);
	connect(viewPlaylistAction, SIGNAL(triggered(bool)), this, SLOT(viewPlaylist(bool)));
	connect(artist_list, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(updateAlbumList(QListWidgetItem *,  QListWidgetItem *)));
	connect(album_list,  SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(updateTitlesList(QListWidgetItem *, QListWidgetItem *)));
	connect(titles_list, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(showTrackInfo(QListWidgetItem *,    QListWidgetItem *)));
	connect(titles_list, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(play(QListWidgetItem *)));
	connect(mw_ok_button,     SIGNAL(clicked()), this, SLOT(hideTrackDetails()));
	connect(qw_top_button,    SIGNAL(clicked()), this, SLOT(moveQueuedTrackToTop()));
	connect(qw_up_button,     SIGNAL(clicked()), this, SLOT(moveQueuedTrackUp()));
	connect(qw_down_button,   SIGNAL(clicked()), this, SLOT(moveQueuedTrackDown()));
	connect(qw_bottom_button, SIGNAL(clicked()), this, SLOT(moveQueuedTrackToBottom()));
	connect(qw_remove_button, SIGNAL(clicked()), this, SLOT(dequeueTrack()));
	connect(qw_ok_button,     SIGNAL(clicked()), this, SLOT(hideTrackQueue()));
	
	//SETUP GUI
	qsrand(QDateTime::currentDateTime().toTime_t());
	setupGUI(Default, "projekt7ui.rc");
	updateArtistList(0);
	
	//READ CONFIG
	config = KGlobal::config();
	KConfigGroup curTrackDetails(config, "curTrackDetails");
	cur_artist = artist_list->item(curTrackDetails.readEntry("artist", QString()).toInt());
	cur_album = curTrackDetails.readEntry("album", QString()).toInt();
	cur_title = curTrackDetails.readEntry("title", QString()).toInt();
	KConfigGroup applicationSettings(config, "applicationSettings");
	viewPlaylistAction->setChecked(applicationSettings.readEntry("playlistVisible", QString()).toInt());
	shuffle_tracks = applicationSettings.readEntry("shuffleTracks", QString()).toInt();
	shuffleAction->setChecked(shuffle_tracks);
	viewCurrentTrack();
	if (titles_list->count() > 0) {
		if (titles_list->currentRow() == -1)
			titles_list->setCurrentRow(0);
		play(titles_list->currentItem()->data(Qt::UserRole).toInt(), false, false);
		pause();
		quint64 song_position = curTrackDetails.readEntry("tick", QString()).toLongLong();
		now_playing->seek(song_position);
		tick(song_position);
		//TODO update the seekSlider's position to match the "tick" location of the song
	}
}