Changeset 55470a5


Ignore:
Timestamp:
06/13/14 14:03:00 (6 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.2, releng/10.0.3, releng/10.1
Children:
d68b62b
Parents:
4a12a2c
Message:

A bit more work on lumina-fm:
1) Add ability to set/use bookmarks (bookmark manager not written yet for deleting bookmarks)
2) Add the ability to switch between all the different sides of the file manager seemlessly (multimedia player, slideshow viewer, zfs file restore), even though those other sides are not put together yet.
3) Add the ability to save/load settings between runs.

Location:
lumina/lumina-fm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lumina/lumina-fm/MainUI.cpp

    rc3ed758 r55470a5  
    44MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ 
    55  ui->setupUi(this); 
     6  //Be careful about the QSettings setup, it must match the lumina-desktop setup 
     7  QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); 
     8  settings = new QSettings( QSettings::UserScope, "LuminaDE", "lumina-fm", this); 
    69  //initialize the non-ui widgets 
    710  tabBar = new QTabBar(this); 
     
    2326  setupIcons(); 
    2427  setupConnections(); 
     28  loadSettings(); 
     29  //Make sure we start on the browser page 
     30  goToBrowserPage(); 
    2531} 
    2632 
     
    5763  ui->actionHome->setIcon( LXDG::findIcon("go-home","") ); 
    5864  ui->actionBookMark->setIcon( LXDG::findIcon("bookmarks","") ); 
     65  ui->actionBackToBrowser->setIcon( LXDG::findIcon("go-previous","") ); 
     66  ui->actionManage_Bookmarks->setIcon( LXDG::findIcon("bookmarks-organize","") ); 
    5967  //Browser page 
     68  ui->tool_addToDir->setIcon( LXDG::findIcon("folder-new","") ); 
    6069  ui->tool_goToImages->setIcon( LXDG::findIcon("fileview-preview","") ); 
    6170  ui->tool_goToPlayer->setIcon( LXDG::findIcon("applications-multimedia","") ); 
     
    6877  ui->tool_image_goPrev->setIcon( LXDG::findIcon("go-previous-view","") ); 
    6978  ui->tool_image_goNext->setIcon( LXDG::findIcon("go-next-view","") ); 
     79   
    7080  //ZFS Restore page 
    7181  ui->tool_zfs_nextSnap->setIcon( LXDG::findIcon("go-next-view","") ); 
     
    8090  connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)) ); 
    8191  connect(ui->tree_dir_view, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OpenContextMenu(const QPoint&)) ); 
     92  connect(ui->menuBookmarks, SIGNAL(triggered(QAction*)), this, SLOT(goToBookmark(QAction*)) ); 
    8293  //Tree Widget interaction 
    8394  connect(ui->tree_dir_view, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(ItemRun(const QModelIndex &)) ); 
     95         
     96  //Page Switching 
     97  connect(ui->tool_goToPlayer, SIGNAL(clicked()), this, SLOT(goToMultimediaPage()) ); 
     98  connect(ui->tool_goToRestore, SIGNAL(clicked()), this, SLOT(goToRestorePage()) ); 
     99  connect(ui->tool_goToImages, SIGNAL(clicked()), this, SLOT(goToSlideshowPage()) ); 
     100  connect(ui->actionBackToBrowser, SIGNAL(triggered()), this, SLOT(goToBrowserPage()) ); 
     101} 
     102 
     103void MainUI::loadSettings(){ 
     104  //Note: make sure this is run after all the UI elements are created and connected to slots 
     105  // but before the first directory gets loaded 
     106  ui->actionView_Hidden_Files->setChecked( settings->value("showhidden", false).toBool() ); 
     107   
     108  //Create the bookmarks menu 
     109  ui->menuBookmarks->clear(); 
     110    ui->menuBookmarks->addAction(ui->actionManage_Bookmarks); 
     111    ui->menuBookmarks->addSeparator(); 
     112  QStringList BM = settings->value("bookmarks", QStringList()).toStringList(); 
     113  bool changed = false; 
     114  for(int i=0; i<BM.length(); i++){ 
     115    if(QFile::exists(BM[i].section("::::",1,1)) ){ 
     116      QAction *act = new QAction(BM[i].section("::::",0,0),this); 
     117        act->setWhatsThis(BM[i].section("::::",1,1)); 
     118      ui->menuBookmarks->addAction(act); 
     119    }else{ 
     120      //Invalid directory - remove the bookmark 
     121      BM.removeAt(i); 
     122      i--; 
     123      changed = true; 
     124    } 
     125  } 
     126  if(changed){ settings->setValue("bookmarks",BM); } 
    84127} 
    85128 
     
    125168  ui->actionUpDir->setEnabled(dir!="/"); 
    126169  ui->actionBack->setEnabled(history.length() > 1); 
     170  ui->actionBookMark->setEnabled( rawdir!=QDir::homePath() && settings->value("bookmarks", QStringList()).toStringList().filter("::::"+rawdir).length()<1 ); 
    127171} 
    128172 
     
    133177//General page switching 
    134178void MainUI::goToMultimediaPage(){ 
    135          
     179  //Make toolbar items disappear appropriately   
     180  ui->actionBackToBrowser->setVisible(true); 
     181  ui->actionBack->setVisible(false); 
     182  ui->actionUpDir->setVisible(false); 
     183  ui->actionHome->setVisible(false); 
     184  ui->actionBookMark->setVisible(false); 
     185  currentDir->setEnabled(false); 
     186  //Disable all the UI elements specifically for the Browser side of things 
     187  ui->actionNew_Tab->setEnabled(false); 
     188  ui->menuEdit->setEnabled(false); 
     189  ui->menuView->setEnabled(false); 
     190  ui->menuBookmarks->setEnabled(false); 
     191  ui->menuExternal_Devices->setEnabled(false); 
     192  //Now go to the Multimedia player 
     193  ui->stackedWidget->setCurrentWidget(ui->page_audioPlayer); 
    136194} 
    137195 
    138196void MainUI::goToRestorePage(){ 
    139          
     197  //Make toolbar items disappear appropriately 
     198  ui->actionBackToBrowser->setVisible(true);     
     199  ui->actionBack->setVisible(false); 
     200  ui->actionUpDir->setVisible(false); 
     201  ui->actionHome->setVisible(false); 
     202  ui->actionBookMark->setVisible(false); 
     203  currentDir->setEnabled(false); 
     204  //Disable all the UI elements specifically for the Browser side of things 
     205  ui->actionNew_Tab->setEnabled(false); 
     206  ui->menuEdit->setEnabled(false); 
     207  ui->menuView->setEnabled(false); 
     208  ui->menuBookmarks->setEnabled(false); 
     209  ui->menuExternal_Devices->setEnabled(false); 
     210  //Now go to the file restore page 
     211  ui->stackedWidget->setCurrentWidget(ui->page_zfs);     
    140212} 
    141213 
    142214void MainUI::goToSlideshowPage(){ 
    143          
     215  //Make toolbar items disappear appropriately   
     216  ui->actionBackToBrowser->setVisible(true); 
     217  ui->actionBack->setVisible(false); 
     218  ui->actionUpDir->setVisible(false); 
     219  ui->actionHome->setVisible(false); 
     220  ui->actionBookMark->setVisible(false); 
     221  currentDir->setEnabled(false); 
     222  //Disable all the UI elements specifically for the Browser side of things 
     223  ui->actionNew_Tab->setEnabled(false); 
     224  ui->menuEdit->setEnabled(false); 
     225  ui->menuView->setEnabled(false); 
     226  ui->menuBookmarks->setEnabled(false); 
     227  ui->menuExternal_Devices->setEnabled(false); 
     228  //Now go to the Slideshow player 
     229  ui->stackedWidget->setCurrentWidget(ui->page_image_view);      
    144230} 
    145231 
    146232void MainUI::goToBrowserPage(){ 
    147          
     233  //Make toolbar items re-appear appropriately   
     234  ui->actionBackToBrowser->setVisible(false); 
     235  ui->actionBack->setVisible(true); 
     236  ui->actionUpDir->setVisible(true); 
     237  ui->actionHome->setVisible(true); 
     238  ui->actionBookMark->setVisible(true); 
     239  currentDir->setEnabled(true); 
     240  //Disable all the UI elements specifically for the Browser side of things 
     241  ui->actionNew_Tab->setEnabled(true); 
     242  ui->menuEdit->setEnabled(true); 
     243  ui->menuView->setEnabled(true); 
     244  ui->menuBookmarks->setEnabled(true); 
     245  ui->menuExternal_Devices->setEnabled(true); 
     246  //Now go to the browser 
     247  ui->stackedWidget->setCurrentWidget(ui->page_browser);         
    148248} 
    149249         
     
    151251void MainUI::on_actionNew_Tab_triggered(){ 
    152252  OpenDirs(QStringList() << QDir::homePath()); 
     253} 
     254 
     255void MainUI::goToBookmark(QAction *act){ 
     256  if(act==ui->actionManage_Bookmarks){ 
     257    qDebug() << "Bookmark Manager not implemented yet!"; 
     258  }else{ 
     259    setCurrentDir(act->whatsThis()); 
     260  } 
    153261} 
    154262 
     
    173281 
    174282void MainUI::on_actionBookMark_triggered(){ 
    175          
     283  QString dir = getCurrentDir(); 
     284  bool ok = false; 
     285  QString name = QInputDialog::getText(this, tr("New Bookmark"), tr("Name:"), QLineEdit::Normal, dir, \ 
     286                &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly); 
     287  if(!ok || name.isEmpty()){ return; } //cancelled 
     288  QStringList BM = settings->value("bookmarks",QStringList()).toStringList(); 
     289  if(BM.filter(name+"::::").length() >0){ 
     290    QMessageBox::warning(this, tr("Invalid Name"), tr("This bookmark name already exists. Please choose another.") ); 
     291    QTimer::singleShot(0,this, SLOT(on_actionBookMark_triggered())); 
     292    return; 
     293  } 
     294  BM.append(name+"::::"+dir); 
     295  BM.sort(); //sort alphabetically by name 
     296  settings->setValue("bookmarks", BM); 
     297  //Now rebuild the bookmarks menu 
     298  ui->menuBookmarks->clear(); 
     299    ui->menuBookmarks->addAction(ui->actionManage_Bookmarks); 
     300    ui->menuBookmarks->addSeparator(); 
     301  bool changed = false; 
     302  for(int i=0; i<BM.length(); i++){ 
     303    if(QFile::exists(BM[i].section("::::",1,1)) ){ 
     304      QAction *act = new QAction(BM[i].section("::::",0,0),this); 
     305        act->setWhatsThis(BM[i].section("::::",1,1)); 
     306      ui->menuBookmarks->addAction(act); 
     307    }else{ 
     308      //Invalid directory - remove the bookmark 
     309      BM.removeAt(i); 
     310      i--; 
     311      changed = true; 
     312    } 
     313  } 
     314  if(changed){ settings->setValue("bookmarks",BM); } 
     315  ui->actionBookMark->setEnabled(false); //already bookmarked 
    176316} 
    177317 
    178318//Browser Functions 
     319void MainUI::on_tool_addToDir_clicked(){ 
     320  bool ok = false; 
     321  QString newdir = QInputDialog::getText(this, tr("New Directory"), tr("Name:"), QLineEdit::Normal, "", \ 
     322                &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly); 
     323  if(!ok || newdir.isEmpty()){ return; } 
     324  QString full = getCurrentDir(); 
     325  if(!full.endsWith("/")){ full.append("/"); } 
     326  QDir dir(full); //open the current dir 
     327  full.append(newdir); //append the new name to the current dir 
     328  //Verify that the new dir does not already exist 
     329  if(dir.exists(full)){ 
     330    QMessageBox::warning(this, tr("Invalid Name"), tr("A file or directory with that name already exists! Please pick a different name.")); 
     331    QTimer::singleShot(0,this, SLOT(on_tool_addToDir_clicked()) ); //repeat this function 
     332  }else{ 
     333    if(!dir.mkdir(newdir) ){ 
     334      QMessageBox::warning(this, tr("Error Creating Directory"), tr("The directory could not be created. Please ensure that you have the proper permissions to modify the current directory.")); 
     335    } 
     336  } 
     337} 
     338 
    179339void MainUI::tabChanged(int tab){ 
    180340  //Load the directory contained in the new tab 
     
    209369  CItem = ui->tree_dir_view->indexAt(pt); 
    210370  if(!CItem.isValid()){ return; } 
     371  //Create the context menu for this particular item 
    211372  contextMenu->clear(); 
    212373  if(fsmod->isDir(CItem)){ 
     
    216377    contextMenu->addAction(tr("Open With..."), this, SLOT(OpenItemWith()) ); 
    217378  } 
     379  contextMenu->addSeparator(); 
     380  contextMenu->addAction(LXDG::findIcon("list-remove",""), tr("Delete"), this, SLOT(RemoveItem()) ); 
    218381  contextMenu->popup(ui->tree_dir_view->mapToGlobal(pt)); 
    219382} 
     
    226389  baseDir.append(fname); 
    227390  qDebug() << "Opening File:" << baseDir; 
    228   QProcess::startDetached("lumina-open "+baseDir); 
     391  QProcess::startDetached("lumina-open \""+baseDir+"\""); 
    229392} 
    230393 
     
    236399  baseDir.append(fname); 
    237400  qDebug() << "Opening File:" << baseDir; 
    238   QProcess::startDetached("lumina-open -select "+baseDir);       
     401  QProcess::startDetached("lumina-open -select \""+baseDir+"\"");        
    239402} 
    240403 
     
    248411} 
    249412 
     413void MainUI::RemoveItem(){ 
     414  if(!CItem.isValid()){ return; } 
     415  QModelIndex index = CItem; //save this for the moment - since the CItem might get cleared in a couple seconds 
     416  QString fname = fsmod->fileName(index); 
     417  QString baseDir = getCurrentDir(); 
     418  if(!baseDir.endsWith("/")){ baseDir.append("/"); } 
     419  baseDir.append(fname); 
     420  //Verify permanent removal of file/dir 
     421  if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file/directory from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+fname, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ 
     422    return; //cancelled 
     423  } 
     424  //Now remove the file/dir 
     425  bool ok = false; 
     426  qDebug() << "Delete: "<<baseDir; 
     427  if(fsmod->isDir(index)){ 
     428    qDebug() << " - Note: Recursive directory deletion not implemented yet!"; 
     429    ok = fsmod->rmdir(index); 
     430  }else{ 
     431    ok = fsmod->remove(index); 
     432  } 
     433  if(!ok){ 
     434    QMessageBox::warning(this, tr("Removal Failure"), tr("The file or directory could not be deleted. Please check that you have the proper permissions to delete it.")); 
     435  } 
     436} 
     437 
    250438void MainUI::RunInMediaPlayer(){ //open in the media player 
    251439         
  • lumina/lumina-fm/MainUI.h

    rc3ed758 r55470a5  
    1111#include <QProcess> 
    1212#include <QSettings> 
     13#include <QInputDialog> 
     14#include <QMessageBox> 
     15#include <QDir> 
     16#include <QTimer> 
    1317 
    1418// libLumina includes 
     
    3640        QFileSystemModel *fsmod; 
    3741        QMenu *contextMenu; 
    38         QSettings *settings; 
     42 
    3943 
    4044        //Internal variables 
     
    4246        QStringList snaps; //names of the snapshots corresponding to snapDirs 
    4347        QModelIndex CItem; //the item that was right-clicked (for the context menu) 
     48        QSettings *settings; 
    4449 
    4550        //Simplification Functions 
    4651        void setupIcons();              //used during initialization 
    4752        void setupConnections();        //used during initialization 
     53        void loadSettings();            //used during initialization 
     54 
    4855        void loadBrowseDir(QString); 
    4956        void loadSnapshot(QString); 
    5057        bool findSnapshotDir(); //returns true if the current dir has snapshots available 
     58         
     59        //Functions to get/set the currently active directory 
    5160        QString getCurrentDir(); 
    5261        void setCurrentDir(QString); 
     
    6776        //Menu Actions 
    6877        void on_actionNew_Tab_triggered(); 
     78        void goToBookmark(QAction*); 
    6979         
    7080        //Toolbar Actions 
     
    7585 
    7686        //Browser Functions 
     87        void on_tool_addToDir_clicked(); 
    7788        void tabChanged(int tab); 
    7889        void tabClosed(int tab); 
     
    8495        void OpenItemWith(); //run "lumina-open -select" on it 
    8596        void OpenDir(); //open the dir in a new tab 
     97        void RemoveItem(); //Remove the item permanently 
    8698        void RunInMediaPlayer(); //open in the media player 
    8799        void RunInSlideShow(); //open in slideshow viewer 
  • lumina/lumina-fm/MainUI.ui

    r58138a3 r55470a5  
    1919     <widget class="QStackedWidget" name="stackedWidget"> 
    2020      <property name="currentIndex"> 
    21        <number>0</number> 
     21       <number>2</number> 
    2222      </property> 
    2323      <widget class="QWidget" name="page_browser"> 
     
    3333             <number>0</number> 
    3434            </property> 
     35            <item> 
     36             <widget class="QToolButton" name="tool_addToDir"> 
     37              <property name="text"> 
     38               <string notr="true">&amp;New Dir</string> 
     39              </property> 
     40              <property name="shortcut"> 
     41               <string>Ctrl+N</string> 
     42              </property> 
     43              <property name="popupMode"> 
     44               <enum>QToolButton::InstantPopup</enum> 
     45              </property> 
     46              <property name="toolButtonStyle"> 
     47               <enum>Qt::ToolButtonTextBesideIcon</enum> 
     48              </property> 
     49              <property name="autoRaise"> 
     50               <bool>true</bool> 
     51              </property> 
     52             </widget> 
     53            </item> 
    3554            <item> 
    3655             <widget class="QLabel" name="label_dir_stats"> 
     
    4261              </property> 
    4362              <property name="text"> 
    44                <string notr="true">Directory Status</string> 
     63               <string notr="true"/> 
    4564              </property> 
    4665             </widget> 
     
    5271              </property> 
    5372              <property name="text"> 
    54                <string>...</string> 
     73               <string>Play</string> 
     74              </property> 
     75              <property name="toolButtonStyle"> 
     76               <enum>Qt::ToolButtonTextBesideIcon</enum> 
    5577              </property> 
    5678              <property name="autoRaise"> 
     
    6587              </property> 
    6688              <property name="text"> 
    67                <string>...</string> 
     89               <string>Slideshow</string> 
     90              </property> 
     91              <property name="toolButtonStyle"> 
     92               <enum>Qt::ToolButtonTextBesideIcon</enum> 
    6893              </property> 
    6994              <property name="autoRaise"> 
     
    78103              </property> 
    79104              <property name="text"> 
    80                <string>...</string> 
     105               <string>Backups</string> 
     106              </property> 
     107              <property name="toolButtonStyle"> 
     108               <enum>Qt::ToolButtonTextBesideIcon</enum> 
    81109              </property> 
    82110              <property name="autoRaise"> 
     
    173201        </item> 
    174202        <item> 
    175          <layout class="QHBoxLayout" name="horizontalLayout_5"> 
    176           <item> 
    177            <widget class="QLabel" name="label_image_name"> 
    178             <property name="font"> 
    179              <font> 
    180               <weight>75</weight> 
    181               <bold>true</bold> 
    182              </font> 
    183             </property> 
    184             <property name="text"> 
    185              <string notr="true">File Name</string> 
    186             </property> 
    187             <property name="alignment"> 
    188              <set>Qt::AlignCenter</set> 
    189             </property> 
    190            </widget> 
    191           </item> 
    192          </layout> 
    193         </item> 
    194         <item> 
    195203         <layout class="QHBoxLayout" name="horizontalLayout_3"> 
    196204          <item> 
     
    238246             <enum>Qt::Horizontal</enum> 
    239247            </property> 
     248           </widget> 
     249          </item> 
     250          <item> 
     251           <widget class="QComboBox" name="combo_image_name"> 
     252            <property name="font"> 
     253             <font> 
     254              <weight>75</weight> 
     255              <bold>true</bold> 
     256             </font> 
     257            </property> 
     258            <property name="frame"> 
     259             <bool>true</bool> 
     260            </property> 
     261            <item> 
     262             <property name="text"> 
     263              <string>File Name</string> 
     264             </property> 
     265            </item> 
    240266           </widget> 
    241267          </item> 
     
    465491     <string>Bookmarks</string> 
    466492    </property> 
     493    <addaction name="actionManage_Bookmarks"/> 
     494   </widget> 
     495   <widget class="QMenu" name="menuExternal_Devices"> 
     496    <property name="title"> 
     497     <string>External Devices</string> 
     498    </property> 
     499    <addaction name="actionScan"/> 
     500    <addaction name="separator"/> 
    467501   </widget> 
    468502   <addaction name="menuFile"/> 
     
    470504   <addaction name="menuView"/> 
    471505   <addaction name="menuBookmarks"/> 
     506   <addaction name="menuExternal_Devices"/> 
    472507  </widget> 
    473508  <widget class="QStatusBar" name="statusbar"/> 
     
    488523    <bool>false</bool> 
    489524   </attribute> 
     525   <addaction name="actionBackToBrowser"/> 
    490526   <addaction name="actionBack"/> 
    491527   <addaction name="actionUpDir"/> 
     
    498534   </property> 
    499535  </action> 
    500   <action name="actionClose_Tab"> 
    501    <property name="text"> 
    502     <string>Close Tab</string> 
    503    </property> 
    504   </action> 
    505536  <action name="actionClose"> 
    506537   <property name="text"> 
     
    511542   <property name="text"> 
    512543    <string>&amp;Preferences</string> 
    513    </property> 
    514   </action> 
    515   <action name="actionShortcut_Locations"> 
    516    <property name="checkable"> 
    517     <bool>true</bool> 
    518    </property> 
    519    <property name="checked"> 
    520     <bool>true</bool> 
    521    </property> 
    522    <property name="text"> 
    523     <string>Shortcuts</string> 
    524    </property> 
    525   </action> 
    526   <action name="actionMusic_Player"> 
    527    <property name="checkable"> 
    528     <bool>true</bool> 
    529    </property> 
    530    <property name="checked"> 
    531     <bool>true</bool> 
    532    </property> 
    533    <property name="text"> 
    534     <string>Music Player</string> 
    535    </property> 
    536   </action> 
    537   <action name="actionImage_Viewer"> 
    538    <property name="checkable"> 
    539     <bool>true</bool> 
    540    </property> 
    541    <property name="checked"> 
    542     <bool>true</bool> 
    543    </property> 
    544    <property name="text"> 
    545     <string>Image Viewer</string> 
    546544   </property> 
    547545  </action> 
     
    598596   <property name="toolTip"> 
    599597    <string>Bookmark this directory</string> 
     598   </property> 
     599  </action> 
     600  <action name="actionScan"> 
     601   <property name="text"> 
     602    <string>Scan</string> 
     603   </property> 
     604  </action> 
     605  <action name="actionBackToBrowser"> 
     606   <property name="text"> 
     607    <string notr="true">BBack</string> 
     608   </property> 
     609   <property name="iconText"> 
     610    <string notr="true">BBack</string> 
     611   </property> 
     612   <property name="toolTip"> 
     613    <string>Back to the system</string> 
     614   </property> 
     615  </action> 
     616  <action name="actionManage_Bookmarks"> 
     617   <property name="enabled"> 
     618    <bool>false</bool> 
     619   </property> 
     620   <property name="text"> 
     621    <string>Manage Bookmarks</string> 
     622   </property> 
     623   <property name="whatsThis"> 
     624    <string notr="true"/> 
    600625   </property> 
    601626  </action> 
Note: See TracChangeset for help on using the changeset viewer.