//=========================================== // Lumina-DE source code // Copyright (c) 2014, Ken Moore // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== #include "MainUI.h" #include "ui_MainUI.h" MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); //Be careful about the QSettings setup, it must match the lumina-desktop setup QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); settings = new QSettings( QSettings::UserScope, "LuminaDE", "lumina-fm", this); favdir = QDir::homePath()+"/.lumina/favorites/"; //save this for later //Reset the UI to the previously used size (if possible) int height = settings->value("geometry/height",-1).toInt(); if(height>100 && height <= QApplication::desktop()->availableGeometry(this).height()){ this->resize(this->width(), height); } int width = settings->value("geometry/width",-1).toInt(); if(width>100 && width <= QApplication::desktop()->availableGeometry(this).width()){ this->resize(width, this->height() ); } //initialize the non-ui widgets tabBar = new QTabBar(this); tabBar->setTabsClosable(true); tabBar->setMovable(true); //tabs are independant - so allow the user to sort them tabBar->setShape(QTabBar::RoundedNorth); tabBar->setFocusPolicy(Qt::NoFocus); ui->verticalLayout_browser->insertWidget(0,tabBar); currentDir = new QLineEdit(this); ui->toolBar->insertWidget(ui->actionBookMark, currentDir); currentDir->setFocusPolicy(Qt::StrongFocus); workThread = new QThread; workThread->setObjectName("Lumina-fm filesystem worker"); worker = new BackgroundWorker; worker->moveToThread(workThread); fsmod = new QFileSystemModel(this); fsmod->setRootPath("/"); ui->tree_dir_view->setModel(fsmod); ui->tree_dir_view->sortByColumn(0, Qt::AscendingOrder); ui->tree_dir_view->setColumnWidth(0,200); ui->tree_dir_view->setColumnWidth(1,80); //size column should be small ui->tree_dir_view->setColumnWidth(2,80); //type column should be small ui->list_dir_view->setModel(fsmod); dirCompleter = new QCompleter(fsmod, this); dirCompleter->setModelSorting( QCompleter::CaseInsensitivelySortedModel ); currentDir->setCompleter(dirCompleter); snapmod = new QFileSystemModel(this); ui->tree_zfs_dir->setModel(snapmod); ui->tree_zfs_dir->sortByColumn(0, Qt::AscendingOrder); iconProv = new MimeIconProvider(); fsmod->setIconProvider(iconProv); snapmod->setIconProvider(iconProv); contextMenu = new QMenu(this); radio_view_details = new QRadioButton(tr("Detailed List"), this); radio_view_list = new QRadioButton(tr("Basic List"), this); radio_view_icons = new QRadioButton(tr("Icons"), this); detWA = new QWidgetAction(this); detWA->setDefaultWidget(radio_view_details); listWA = new QWidgetAction(this); listWA->setDefaultWidget(radio_view_list); icoWA = new QWidgetAction(this); icoWA->setDefaultWidget(radio_view_icons); ui->menuView->addAction(detWA); ui->menuView->addAction(listWA); ui->menuView->addAction(icoWA); //Setup the special Phonon widgets mediaObj = new Phonon::MediaObject(this); mediaObj->setTickInterval(200); //1/5 second ticks for updates videoDisplay = new Phonon::VideoWidget(this); videoDisplay->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); ui->videoLayout->addWidget(videoDisplay); Phonon::createPath(mediaObj, videoDisplay); videoDisplay->setVisible(false); audioOut = new Phonon::AudioOutput(Phonon::VideoCategory, this); Phonon::createPath(mediaObj, audioOut); playerSlider = new Phonon::SeekSlider(this); playerSlider->setMediaObject(mediaObj); ui->videoControlLayout->insertWidget(4, playerSlider); ui->tool_player_stop->setEnabled(false); //nothing to stop yet ui->tool_player_pause->setVisible(false); //nothing to pause yet //Setup any specialty keyboard shortcuts nextTabLShort = new QShortcut( QKeySequence(tr("Shift+Left")), this); nextTabRShort = new QShortcut( QKeySequence(tr("Shift+Right")), this); closeTabShort = new QShortcut( QKeySequence(tr("Ctrl+W")), this); copyFilesShort = new QShortcut( QKeySequence(tr("Ctrl+C")), this); pasteFilesShort = new QShortcut( QKeySequence(tr("Ctrl+V")), this); deleteFilesShort = new QShortcut( QKeySequence(tr("Delete")), this); //Finish loading the interface workThread->start(); setupIcons(); setupConnections(); loadSettings(); RebuildBookmarksMenu(); RebuildDeviceMenu(); //Make sure we start on the browser page goToBrowserPage(); } MainUI::~MainUI(){ workThread->quit(); workThread->wait(); } void MainUI::OpenDirs(QStringList dirs){ for(int i=0; iaddTab( dirs[i].section("/",-1) ); tabBar->setTabWhatsThis( index, dirs[i] ); if(index==0){ setCurrentDir(dirs[i]); }//display this as the current dir } tabBar->setVisible( tabBar->count() > 1 ); } //========== // PRIVATE //========== void MainUI::setupIcons(){ this->setWindowIcon( LXDG::findIcon("Insight-FileManager","") ); //Setup all the icons using libLumina ui->actionClose->setIcon( LXDG::findIcon("application-exit","") ); ui->actionNew_Tab->setIcon( LXDG::findIcon("tab-new-background","") ); //ui->action_Preferences->setIcon( LXDG::findIcon("configure","") ); ui->actionUpDir->setIcon( LXDG::findIcon("go-up","") ); ui->actionBack->setIcon( LXDG::findIcon("go-previous","") ); ui->actionHome->setIcon( LXDG::findIcon("go-home","") ); ui->actionBookMark->setIcon( LXDG::findIcon("bookmarks","") ); ui->actionBackToBrowser->setIcon( LXDG::findIcon("go-previous","") ); ui->actionManage_Bookmarks->setIcon( LXDG::findIcon("bookmarks-organize","") ); ui->actionScan->setIcon( LXDG::findIcon("system-search","") ); //Browser page ui->tool_addToDir->setIcon( LXDG::findIcon("folder-new","") ); ui->tool_goToImages->setIcon( LXDG::findIcon("fileview-preview","") ); ui->tool_goToPlayer->setIcon( LXDG::findIcon("applications-multimedia","") ); ui->tool_goToRestore->setIcon( LXDG::findIcon("document-revert","") ); ui->tool_act_run->setIcon( LXDG::findIcon("run-build-file","") ); ui->tool_act_runwith->setIcon( LXDG::findIcon("run-build-configure","") ); ui->tool_act_cut->setIcon( LXDG::findIcon("edit-cut","") ); ui->tool_act_copy->setIcon( LXDG::findIcon("edit-copy","") ); ui->tool_act_paste->setIcon( LXDG::findIcon("edit-paste","") ); ui->tool_act_rename->setIcon( LXDG::findIcon("edit-rename","") ); ui->tool_act_rm->setIcon( LXDG::findIcon("edit-delete","") ); ui->tool_act_fav->setIcon( LXDG::findIcon("quickopen","") ); //Multimedia Player page ui->tool_player_next->setIcon( LXDG::findIcon("media-skip-forward","") ); ui->tool_player_prev->setIcon( LXDG::findIcon("media-skip-backward","") ); ui->tool_player_pause->setIcon( LXDG::findIcon("media-playback-pause","") ); ui->tool_player_play->setIcon( LXDG::findIcon("media-playback-start","") ); ui->tool_player_stop->setIcon( LXDG::findIcon("media-playback-stop","") ); //Slideshow page ui->tool_image_goBegin->setIcon( LXDG::findIcon("go-first-view","") ); ui->tool_image_goEnd->setIcon( LXDG::findIcon("go-last-view","") ); ui->tool_image_goPrev->setIcon( LXDG::findIcon("go-previous-view","") ); ui->tool_image_goNext->setIcon( LXDG::findIcon("go-next-view","") ); //ZFS Restore page ui->tool_zfs_nextSnap->setIcon( LXDG::findIcon("go-next-view","") ); ui->tool_zfs_prevSnap->setIcon( LXDG::findIcon("go-previous-view","") ); ui->tool_zfs_restoreItem->setIcon( LXDG::findIcon("document-revert","") ); } void MainUI::setupConnections(){ connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(startEditDir(QWidget*, QWidget*)) ); connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)) ); connect(ui->menuBookmarks, SIGNAL(triggered(QAction*)), this, SLOT(goToBookmark(QAction*)) ); connect(ui->menuExternal_Devices, SIGNAL(triggered(QAction*)), this, SLOT(goToDevice(QAction*)) ); connect(currentDir, SIGNAL(returnPressed()), this, SLOT(goToDirectory())); connect(radio_view_details, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); connect(radio_view_list, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); connect(radio_view_icons, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool)) ); //Background worker class connect(this, SIGNAL(DirChanged(QString)), worker, SLOT(startDirChecks(QString)) ); connect(worker, SIGNAL(ImagesAvailable(QStringList)), this, SLOT(AvailablePictures(QStringList)) ); connect(worker, SIGNAL(MultimediaAvailable(QStringList)), this, SLOT(AvailableMultimediaFiles(QStringList)) ); connect(worker, SIGNAL(SnapshotsAvailable(QString, QStringList)), this, SLOT(AvailableBackups(QString, QStringList)) ); //Action buttons on browser page connect(ui->tool_act_run, SIGNAL(clicked()), this, SLOT(OpenItem()) ); connect(ui->tool_act_runwith, SIGNAL(clicked()), this, SLOT(OpenItemWith()) ); connect(ui->tool_act_rm, SIGNAL(clicked()), this, SLOT(RemoveItem()) ); connect(ui->tool_act_rename, SIGNAL(clicked()), this, SLOT(RenameItem()) ); connect(ui->tool_act_paste, SIGNAL(clicked()), this, SLOT(PasteItems()) ); connect(ui->tool_act_cut, SIGNAL(clicked()), this, SLOT(CutItems()) ); connect(ui->tool_act_copy, SIGNAL(clicked()), this, SLOT(CopyItems()) ); connect(ui->tool_act_fav, SIGNAL(clicked()), this, SLOT(FavoriteItem()) ); //Tree Widget interaction connect(ui->tree_dir_view, SIGNAL(activated(const QModelIndex&)), this, SLOT(ItemRun(const QModelIndex&)) ); connect(ui->list_dir_view, SIGNAL(activated(const QModelIndex&)), this, SLOT(ItemRun(const QModelIndex&)) ); connect(ui->tree_dir_view, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OpenContextMenu(const QPoint&)) ); connect(ui->list_dir_view, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OpenContextMenu(const QPoint&)) ); connect(ui->tree_dir_view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)), this, SLOT(ItemSelectionChanged()) ); connect(ui->list_dir_view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection, const QItemSelection)), this, SLOT(ItemSelectionChanged()) ); //Page Switching connect(ui->tool_goToPlayer, SIGNAL(clicked()), this, SLOT(goToMultimediaPage()) ); connect(ui->tool_goToRestore, SIGNAL(clicked()), this, SLOT(goToRestorePage()) ); connect(ui->tool_goToImages, SIGNAL(clicked()), this, SLOT(goToSlideshowPage()) ); connect(ui->actionBackToBrowser, SIGNAL(triggered()), this, SLOT(goToBrowserPage()) ); //Slideshow page connect(ui->combo_image_name, SIGNAL(currentIndexChanged(int)), this, SLOT(showNewPicture()) ); connect(ui->tool_image_goBegin, SIGNAL(clicked()), this, SLOT(firstPicture()) ); connect(ui->tool_image_goEnd, SIGNAL(clicked()), this, SLOT(lastPicture()) ); connect(ui->tool_image_goNext, SIGNAL(clicked()), this, SLOT(nextPicture()) ); connect(ui->tool_image_goPrev, SIGNAL(clicked()), this, SLOT(prevPicture()) ); //ZFS Restore page connect(ui->slider_zfs_snapshot, SIGNAL(valueChanged(int)), this, SLOT(showSnapshot()) ); connect(ui->tool_zfs_nextSnap, SIGNAL(clicked()), this, SLOT(nextSnapshot()) ); connect(ui->tool_zfs_prevSnap, SIGNAL(clicked()), this, SLOT(prevSnapshot()) ); connect(ui->tool_zfs_restoreItem, SIGNAL(clicked()), this, SLOT(restoreItems()) ); //Multimedia Player page connect(ui->tool_player_next, SIGNAL(clicked()), this, SLOT(playerNext())); connect(ui->tool_player_prev, SIGNAL(clicked()), this, SLOT(playerPrevious())); connect(ui->tool_player_pause, SIGNAL(clicked()), this, SLOT(playerPause())); connect(ui->tool_player_play, SIGNAL(clicked()), this, SLOT(playerStart())); connect(ui->tool_player_stop, SIGNAL(clicked()), this, SLOT(playerStop())); connect(ui->combo_player_list, SIGNAL(currentIndexChanged(int)), this, SLOT(playerFileChanged()) ); connect(mediaObj, SIGNAL(finished()), this, SLOT(playerFinished()) ); connect(mediaObj, SIGNAL(tick(qint64)), this, SLOT(playerTimeChanged(qint64)) ); connect(mediaObj, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(playerStateChanged(Phonon::State, Phonon::State)) ); connect(mediaObj, SIGNAL(hasVideoChanged(bool)), this, SLOT(playerVideoAvailable(bool)) ); //Special Keyboard Shortcuts connect(nextTabLShort, SIGNAL(activated()), this, SLOT( prevTab() ) ); connect(nextTabRShort, SIGNAL(activated()), this, SLOT( nextTab() ) ); connect(closeTabShort, SIGNAL(activated()), this, SLOT( tabClosed() ) ); connect(copyFilesShort, SIGNAL(activated()), this, SLOT( CopyItems() ) ); connect(pasteFilesShort, SIGNAL(activated()), this, SLOT( PasteItems() ) ); connect(deleteFilesShort, SIGNAL(activated()), this, SLOT( RemoveItem() ) ); } void MainUI::loadSettings(){ //Note: make sure this is run after all the UI elements are created and connected to slots // but before the first directory gets loaded ui->actionView_Hidden_Files->setChecked( settings->value("showhidden", false).toBool() ); on_actionView_Hidden_Files_triggered(); //make sure to update the models too ui->actionShow_Action_Buttons->setChecked(settings->value("showactions", true).toBool() ); on_actionShow_Action_Buttons_triggered(); //make sure to update the UI QString view = settings->value("viewmode","details").toString(); if(view=="icons"){ radio_view_icons->setChecked(true); } else if(view=="list"){ radio_view_list->setChecked(true); } else{ radio_view_details->setChecked(true); } } void MainUI::RebuildBookmarksMenu(){ //Create the bookmarks menu ui->menuBookmarks->clear(); ui->menuBookmarks->addAction(ui->actionManage_Bookmarks); ui->menuBookmarks->addSeparator(); QStringList BM = settings->value("bookmarks", QStringList()).toStringList(); ui->menuBookmarks->clear(); ui->menuBookmarks->addAction(ui->actionManage_Bookmarks); ui->menuBookmarks->addSeparator(); bool changed = false; BM.sort(); //Sort alphabetically for(int i=0; isetWhatsThis(BM[i].section("::::",1,1)); ui->menuBookmarks->addAction(act); }else{ //Invalid directory - remove the bookmark BM.removeAt(i); i--; changed = true; } } if(changed){ settings->setValue("bookmarks",BM); } ui->actionManage_Bookmarks->setEnabled(BM.length()>0); } void MainUI::RebuildDeviceMenu(){ //Create the External Devices Menu appropriately ui->menuExternal_Devices->clear(); ui->menuExternal_Devices->addAction( ui->actionScan ); ui->menuExternal_Devices->addSeparator(); //Scan for externally mounted devices QStringList devs = LOS::ExternalDevicePaths(); //Output Format: :::::::: (6/24/14 - version 0.4.0 ) // = [USB, HDRIVE, SDCARD, DVD, UNKNOWN] //Now add them to the menu appropriately for(int i=0; i