source: lumina/lumina-fm/MainUI.cpp @ 603a75a

releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2
Last change on this file since 603a75a was 603a75a, checked in by Ken Moore <ken@…>, 11 months ago

Add a ton of keyboard shortcuts to lumina-fm, and also add the ability to manually type/browse directories.

  • Property mode set to 100644
File size: 26.6 KB
Line 
1//===========================================
2//  Lumina-DE source code
3//  Copyright (c) 2014, Ken Moore
4//  Available under the 3-clause BSD license
5//  See the LICENSE file for full details
6//===========================================
7#include "MainUI.h"
8#include "ui_MainUI.h"
9
10MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
11  ui->setupUi(this);
12  //Be careful about the QSettings setup, it must match the lumina-desktop setup
13  QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina");
14  settings = new QSettings( QSettings::UserScope, "LuminaDE", "lumina-fm", this);
15  //initialize the non-ui widgets
16  tabBar = new QTabBar(this);
17    tabBar->setTabsClosable(true);
18    tabBar->setMovable(true); //tabs are independant - so allow the user to sort them
19    tabBar->setShape(QTabBar::RoundedNorth);
20    ui->verticalLayout_browser->insertWidget(0,tabBar);
21  currentDir = new QLineEdit(this);
22    ui->toolBar->insertWidget(ui->actionBookMark, currentDir);
23  fsmod = new QFileSystemModel(this);
24    ui->tree_dir_view->setModel(fsmod);
25    ui->tree_dir_view->setItemsExpandable(false);
26    ui->tree_dir_view->setExpandsOnDoubleClick(false);
27    ui->tree_dir_view->setRootIsDecorated(false);
28    ui->tree_dir_view->setSortingEnabled(true);
29    ui->tree_dir_view->sortByColumn(0,Qt::AscendingOrder);
30    ui->tree_dir_view->setContextMenuPolicy(Qt::CustomContextMenu);
31  dirCompleter = new QCompleter(fsmod, this);
32    currentDir->setCompleter(dirCompleter);
33  snapmod = new QFileSystemModel(this);
34    ui->tree_zfs_dir->setModel(snapmod);
35    ui->tree_zfs_dir->sortByColumn(0, Qt::AscendingOrder);
36  contextMenu = new QMenu(this);
37  //Setup any specialty keyboard shortcuts
38  nextTabLShort = new QShortcut( QKeySequence(tr("Shift+Left")), this);
39  nextTabRShort = new QShortcut( QKeySequence(tr("Shift+Right")), this);
40  closeTabShort = new QShortcut( QKeySequence(tr("Ctrl+W")), this);
41  //Finish loading the interface
42  setupIcons();
43  setupConnections();
44  loadSettings();
45  //Make sure we start on the browser page
46  goToBrowserPage();
47}
48
49MainUI::~MainUI(){
50       
51}
52
53void MainUI::OpenDirs(QStringList dirs){
54  for(int i=0; i<dirs.length(); i++){
55    //Add this directory in a new tab
56    if(dirs[i].endsWith("/")){ dirs[i].chop(1); }
57    qDebug() << "Open Directory:" << dirs[i];
58    int index = tabBar->addTab( dirs[i].section("/",-1) );
59    tabBar->setTabWhatsThis( index, dirs[i] );
60    if(index==0){ setCurrentDir(dirs[i]); }//display this as the current dir
61  }
62  tabBar->setVisible( tabBar->count() > 1 );
63}
64
65//==========
66//    PRIVATE
67//==========
68void MainUI::setupIcons(){
69  this->setWindowIcon( LXDG::findIcon("system-file-manager","") );
70       
71  //Setup all the icons using libLumina
72  ui->actionClose->setIcon( LXDG::findIcon("application-exit","") );
73  ui->actionNew_Tab->setIcon( LXDG::findIcon("tab-new-background","") );
74  ui->action_Preferences->setIcon( LXDG::findIcon("configure","") );
75  ui->actionRefresh->setIcon( LXDG::findIcon("view-refresh","") );
76  ui->actionUpDir->setIcon( LXDG::findIcon("go-up","") );
77  ui->actionBack->setIcon( LXDG::findIcon("go-previous","") );
78  ui->actionHome->setIcon( LXDG::findIcon("go-home","") );
79  ui->actionBookMark->setIcon( LXDG::findIcon("bookmarks","") );
80  ui->actionBackToBrowser->setIcon( LXDG::findIcon("go-previous","") );
81  ui->actionManage_Bookmarks->setIcon( LXDG::findIcon("bookmarks-organize","") );
82  //Browser page
83  ui->tool_addToDir->setIcon( LXDG::findIcon("folder-new","") );
84  ui->tool_goToImages->setIcon( LXDG::findIcon("fileview-preview","") );
85  ui->tool_goToPlayer->setIcon( LXDG::findIcon("applications-multimedia","") );
86  ui->tool_goToRestore->setIcon( LXDG::findIcon("document-revert","") );
87  //Multimedia Player page
88       
89  //Slideshow page
90  ui->tool_image_goBegin->setIcon( LXDG::findIcon("go-first-view","") );
91  ui->tool_image_goEnd->setIcon( LXDG::findIcon("go-last-view","") );
92  ui->tool_image_goPrev->setIcon( LXDG::findIcon("go-previous-view","") );
93  ui->tool_image_goNext->setIcon( LXDG::findIcon("go-next-view","") );
94 
95  //ZFS Restore page
96  ui->tool_zfs_nextSnap->setIcon( LXDG::findIcon("go-next-view","") );
97  ui->tool_zfs_prevSnap->setIcon( LXDG::findIcon("go-previous-view","") );
98  ui->tool_zfs_restoreItem->setIcon( LXDG::findIcon("document-revert","") );
99}
100
101void MainUI::setupConnections(){
102  connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(startEditDir(QWidget*, QWidget*)) );
103  connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) );
104  connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)) );
105  connect(ui->tree_dir_view, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(OpenContextMenu(const QPoint&)) );
106  connect(ui->menuBookmarks, SIGNAL(triggered(QAction*)), this, SLOT(goToBookmark(QAction*)) );
107  connect(currentDir, SIGNAL(returnPressed()), this, SLOT(goToDirectory()));
108       
109  //Tree Widget interaction
110  connect(ui->tree_dir_view, SIGNAL(activated(const QModelIndex &)), this, SLOT(ItemRun(const QModelIndex &)) );
111  connect(fsmod, SIGNAL(directoryLoaded(QString)), this, SLOT(directoryLoaded()) );
112       
113  //Page Switching
114  connect(ui->tool_goToPlayer, SIGNAL(clicked()), this, SLOT(goToMultimediaPage()) );
115  connect(ui->tool_goToRestore, SIGNAL(clicked()), this, SLOT(goToRestorePage()) );
116  connect(ui->tool_goToImages, SIGNAL(clicked()), this, SLOT(goToSlideshowPage()) );
117  connect(ui->actionBackToBrowser, SIGNAL(triggered()), this, SLOT(goToBrowserPage()) );
118       
119  //Slideshow page
120  connect(ui->combo_image_name, SIGNAL(currentIndexChanged(int)), this, SLOT(showNewPicture()) );
121  connect(ui->tool_image_goBegin, SIGNAL(clicked()), this, SLOT(firstPicture()) );
122  connect(ui->tool_image_goEnd, SIGNAL(clicked()), this, SLOT(lastPicture()) );
123  connect(ui->tool_image_goNext, SIGNAL(clicked()), this, SLOT(nextPicture()) );
124  connect(ui->tool_image_goPrev, SIGNAL(clicked()), this, SLOT(prevPicture()) );
125       
126  //ZFS Restore page
127  connect(snapmod, SIGNAL(directoryLoaded(QString)), this, SLOT(snapshotLoaded()) );
128  connect(ui->slider_zfs_snapshot, SIGNAL(valueChanged(int)), this, SLOT(showSnapshot()) );
129  connect(ui->tool_zfs_nextSnap, SIGNAL(clicked()), this, SLOT(nextSnapshot()) );
130  connect(ui->tool_zfs_prevSnap, SIGNAL(clicked()), this, SLOT(prevSnapshot()) );
131  connect(ui->tool_zfs_restoreItem, SIGNAL(clicked()), this, SLOT(restoreItems()) );
132 
133  //Special Keyboard Shortcuts
134  connect(nextTabLShort, SIGNAL(activated()), this, SLOT( prevTab() ) );
135  connect(nextTabRShort, SIGNAL(activated()), this, SLOT( nextTab() ) );
136  connect(closeTabShort, SIGNAL(activated()), this, SLOT( tabClosed() ) );
137}
138
139void MainUI::loadSettings(){
140  //Note: make sure this is run after all the UI elements are created and connected to slots
141  // but before the first directory gets loaded
142  ui->actionView_Hidden_Files->setChecked( settings->value("showhidden", false).toBool() );
143 
144  //Create the bookmarks menu
145  ui->menuBookmarks->clear();
146    ui->menuBookmarks->addAction(ui->actionManage_Bookmarks);
147    ui->menuBookmarks->addSeparator();
148  QStringList BM = settings->value("bookmarks", QStringList()).toStringList();
149  bool changed = false;
150  for(int i=0; i<BM.length(); i++){
151    if(QFile::exists(BM[i].section("::::",1,1)) ){
152      QAction *act = new QAction(BM[i].section("::::",0,0),this);
153        act->setWhatsThis(BM[i].section("::::",1,1));
154      ui->menuBookmarks->addAction(act);
155    }else{
156      //Invalid directory - remove the bookmark
157      BM.removeAt(i);
158      i--;
159      changed = true;
160    }
161  }
162  if(changed){ settings->setValue("bookmarks",BM); }
163}
164
165void MainUI::loadBrowseDir(QString dir){
166  qDebug() << "Load Browse Dir:" << dir;
167}
168
169void MainUI::loadSnapshot(QString dir){
170  qDebug() << "Load Snapshot:" << dir;
171}
172
173bool MainUI::findSnapshotDir(){
174  qDebug() << "Find Snapshot Dir:";
175  return false;
176}
177
178QString MainUI::getCurrentDir(){
179  return currentDir->whatsThis();
180}
181
182void MainUI::setCurrentDir(QString dir){
183  if(dir.isEmpty()){ return; }
184  QFileInfo info(dir);
185  if(!info.isDir() || !info.exists() ){ 
186    qDebug() << "Invalid Directory:" << dir;
187    return; 
188  } //do nothing
189  //qDebug() << "Show Directory:" << dir;
190  isUserWritable = info.isWritable();
191  if(dir.endsWith("/") && dir!="/" ){ dir.chop(1); }
192  currentDir->setWhatsThis(dir); //save the full path internally
193  QString rawdir = dir;
194  //Update the directory viewer and update the line edit
195  ui->tree_dir_view->setRootIndex( fsmod->setRootPath(dir) );
196  dir.replace(QDir::homePath()+"/", "~/");
197  currentDir->setText(dir);
198  //Adjust the tab data
199  tabBar->setTabWhatsThis( tabBar->currentIndex(), rawdir );
200  if(dir!="/"){ tabBar->setTabText( tabBar->currentIndex(), dir.section("/",-1) ); }
201  else{ tabBar->setTabText( tabBar->currentIndex(), dir); }
202  QStringList history = tabBar->tabData(tabBar->currentIndex()).toStringList();
203  if(history.isEmpty() || history.first()!=rawdir){ history.prepend(rawdir); history.removeAll(""); }
204  //qDebug() << "History:" << history;
205  tabBar->setTabData(tabBar->currentIndex(), history);
206  //Now adjust the items as necessary
207  QTimer::singleShot(0, this, SLOT(checkForMultimediaFiles()));
208  QTimer::singleShot(0, this, SLOT(checkForBackups()));
209  QTimer::singleShot(0, this, SLOT(checkForPictures()));
210  ui->actionUpDir->setEnabled(dir!="/");
211  ui->actionBack->setEnabled(history.length() > 1);
212  ui->actionBookMark->setEnabled( rawdir!=QDir::homePath() && settings->value("bookmarks", QStringList()).toStringList().filter("::::"+rawdir).length()<1 );
213}
214
215//==============
216//    PRIVATE SLOTS
217//==============
218//General button check functions
219void MainUI::checkForMultimediaFiles(){
220  ui->tool_goToPlayer->setVisible(false);
221  //Check for multimedia files not implemented yet!     
222}
223
224void MainUI::checkForBackups(){
225  ui->tool_goToRestore->setVisible(false);
226  //Check for ZFS snapshots not implemented yet!
227  snapDirs.clear(); //clear the internal variable
228  if(!isUserWritable){ return; } //cannot restore files into a non-writable directory
229  //Now recursively try to find snapshots of this directory
230  QString cdir = getCurrentDir();
231  QDir dir(cdir);
232  bool found = false;
233  while(dir.absolutePath()!="/" && !found){
234    if(dir.exists(".zfs/snapshot")){ found = true;}
235    else{ dir.cdUp(); }
236  }
237  //Now find the snapshots that contain this directory and save them
238  if(found){
239    QString reldir = getCurrentDir();
240          reldir.remove(dir.absolutePath());
241    dir.cd(".zfs/snapshot");
242    snapDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time);
243    //Check that the current directory exists in each snapshot
244    for(int i=0; i<snapDirs.length(); i++){
245      if( !dir.exists(snapDirs[i]+"/"+reldir) ){
246        snapDirs.removeAt(i);
247        i--;
248      }else{
249        snapDirs[i] = QFileInfo(dir, snapDirs[i]+"/"+reldir).created().toString("yyyyMMddhhmmsszzz")+"::::"+snapDirs[i];
250      }
251    }
252    snapDirs.sort();
253    //Sort the snapshots by time (newest last) and format them
254    for(int i=0; i<snapDirs.length(); i++){
255      snapDirs[i] = dir.absolutePath()+"/"+snapDirs[i].section("::::",1,50)+"/"+reldir;
256    }
257    //qDebug() << "Found snapshots:" << snapDirs;
258  }
259  //Now enable the button if any snapshots available
260  ui->tool_goToRestore->setVisible(!snapDirs.isEmpty());
261}
262
263void MainUI::checkForPictures(){
264  ui->tool_goToImages->setVisible(false);
265  //Check for images not implemented yet!
266  QDir dir(getCurrentDir());
267  QStringList pics = dir.entryList(QStringList() << "*.png" << "*.jpg", QDir::Files | QDir::NoDotAndDotDot, QDir::Name | QDir::IgnoreCase);
268  if(!pics.isEmpty()){
269    ui->combo_image_name->clear();
270    ui->combo_image_name->addItems(pics);
271    ui->tool_goToImages->setVisible(true);       
272  }
273       
274}
275
276//General page switching
277void MainUI::goToMultimediaPage(){
278  //Make toolbar items disappear appropriately 
279  ui->actionBackToBrowser->setVisible(true);
280  ui->actionBack->setVisible(false);
281  ui->actionUpDir->setVisible(false);
282  ui->actionHome->setVisible(false);
283  ui->actionBookMark->setVisible(false);
284  currentDir->setEnabled(false);
285  //Disable all the UI elements specifically for the Browser side of things
286  ui->actionNew_Tab->setEnabled(false);
287  ui->menuEdit->setEnabled(false);
288  ui->menuView->setEnabled(false);
289  ui->menuBookmarks->setEnabled(false);
290  ui->menuExternal_Devices->setEnabled(false);
291  //Now go to the Multimedia player
292  ui->stackedWidget->setCurrentWidget(ui->page_audioPlayer);
293}
294
295void MainUI::goToRestorePage(){
296  //Make toolbar items disappear appropriately
297  ui->actionBackToBrowser->setVisible(true);   
298  ui->actionBack->setVisible(false);
299  ui->actionUpDir->setVisible(false);
300  ui->actionHome->setVisible(false);
301  ui->actionBookMark->setVisible(false);
302  currentDir->setEnabled(false);
303  //Disable all the UI elements specifically for the Browser side of things
304  ui->actionNew_Tab->setEnabled(false);
305  ui->menuEdit->setEnabled(false);
306  ui->menuView->setEnabled(false);
307  ui->menuBookmarks->setEnabled(false);
308  ui->menuExternal_Devices->setEnabled(false);
309  //Load all the info into the file restore page
310  ui->slider_zfs_snapshot->setRange(1,snapDirs.length());
311  ui->slider_zfs_snapshot->setValue(snapDirs.length());
312  //Now go to the file restore page
313  showSnapshot(); //Make sure it is updated for the current directory
314  ui->stackedWidget->setCurrentWidget(ui->page_zfs);   
315}
316
317void MainUI::goToSlideshowPage(){
318  //Make toolbar items disappear appropriately 
319  ui->actionBackToBrowser->setVisible(true);
320  ui->actionBack->setVisible(false);
321  ui->actionUpDir->setVisible(false);
322  ui->actionHome->setVisible(false);
323  ui->actionBookMark->setVisible(false);
324  currentDir->setEnabled(false);
325  //Disable all the UI elements specifically for the Browser side of things
326  ui->actionNew_Tab->setEnabled(false);
327  ui->menuEdit->setEnabled(false);
328  ui->menuView->setEnabled(false);
329  ui->menuBookmarks->setEnabled(false);
330  ui->menuExternal_Devices->setEnabled(false);
331  //Now go to the Slideshow player
332  ui->stackedWidget->setCurrentWidget(ui->page_image_view);
333  showNewPicture(); //make sure it is up to date with the widget size
334}
335
336void MainUI::goToBrowserPage(){
337  //Make toolbar items re-appear appropriately 
338  ui->actionBackToBrowser->setVisible(false);
339  ui->actionBack->setVisible(true);
340  ui->actionUpDir->setVisible(true);
341  ui->actionHome->setVisible(true);
342  ui->actionBookMark->setVisible(true);
343  currentDir->setEnabled(true);
344  //Disable all the UI elements specifically for the Browser side of things
345  ui->actionNew_Tab->setEnabled(true);
346  ui->menuEdit->setEnabled(true);
347  ui->menuView->setEnabled(true);
348  ui->menuBookmarks->setEnabled(true);
349  ui->menuExternal_Devices->setEnabled(true);
350  //Now go to the browser
351  ui->stackedWidget->setCurrentWidget(ui->page_browser);       
352}
353       
354//Menu Actions
355void MainUI::on_actionNew_Tab_triggered(){
356  OpenDirs(QStringList() << QDir::homePath());
357}
358
359void MainUI::on_actionClose_triggered(){
360  if(tabBar->count() > 1){
361    if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Quit"), tr("You have multiple tabs open. Are you sure you want to quit?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes ) ){
362      return;
363    }
364  }
365  qDebug() << "Closing Down...";
366  this->close();
367}
368
369void MainUI::goToBookmark(QAction *act){
370  if(act==ui->actionManage_Bookmarks){
371    qDebug() << "Bookmark Manager not implemented yet!";
372  }else{
373    setCurrentDir(act->whatsThis());
374  }
375}
376
377//Toolbar Actions
378void MainUI::on_actionBack_triggered(){
379  QStringList history = tabBar->tabData(tabBar->currentIndex()).toStringList();
380  if(history.length() <= 1){ return; } //need the second item
381  history.removeAt(0); //remove the first item (the current dir)
382  tabBar->setTabData(tabBar->currentIndex(), history); //re-write the saved history
383  setCurrentDir(history.first()); //go to the previous entry in the history
384}
385
386void MainUI::on_actionUpDir_triggered(){
387  QString dir =  getCurrentDir();
388    dir.chop( dir.section("/",-1).length() );
389    setCurrentDir(dir);
390}
391
392void MainUI::on_actionHome_triggered(){
393  setCurrentDir(QDir::homePath());
394}
395
396void MainUI::on_actionBookMark_triggered(){
397  QString dir = getCurrentDir();
398  bool ok = false;
399  QString name = QInputDialog::getText(this, tr("New Bookmark"), tr("Name:"), QLineEdit::Normal, dir, \
400                &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly);
401  if(!ok || name.isEmpty()){ return; } //cancelled
402  QStringList BM = settings->value("bookmarks",QStringList()).toStringList();
403  if(BM.filter(name+"::::").length() >0){
404    QMessageBox::warning(this, tr("Invalid Name"), tr("This bookmark name already exists. Please choose another.") );
405    QTimer::singleShot(0,this, SLOT(on_actionBookMark_triggered()));
406    return;
407  }
408  BM.append(name+"::::"+dir);
409  BM.sort(); //sort alphabetically by name
410  settings->setValue("bookmarks", BM);
411  //Now rebuild the bookmarks menu
412  ui->menuBookmarks->clear();
413    ui->menuBookmarks->addAction(ui->actionManage_Bookmarks);
414    ui->menuBookmarks->addSeparator();
415  bool changed = false;
416  for(int i=0; i<BM.length(); i++){
417    if(QFile::exists(BM[i].section("::::",1,1)) ){
418      QAction *act = new QAction(BM[i].section("::::",0,0),this);
419        act->setWhatsThis(BM[i].section("::::",1,1));
420      ui->menuBookmarks->addAction(act);
421    }else{
422      //Invalid directory - remove the bookmark
423      BM.removeAt(i);
424      i--;
425      changed = true;
426    }
427  }
428  if(changed){ settings->setValue("bookmarks",BM); }
429  ui->actionBookMark->setEnabled(false); //already bookmarked
430}
431
432//Browser Functions
433void MainUI::startEditDir(QWidget *old, QWidget *now){
434  if(now==currentDir){
435    //The dir edit just got focus
436    QString dir = currentDir->text();
437      dir.replace("~/", QDir::homePath()+"/");
438      currentDir->setText(dir);
439      //Try to move to the end
440      currentDir->selectAll();
441  }else if(old==currentDir){
442    QString dir = currentDir->text();
443      dir.replace(QDir::homePath()+"/", "~/");
444      currentDir->setText(dir);
445  }
446}
447
448void MainUI::goToDirectory(){
449  QString dir = currentDir->text();
450  dir.replace("~/",QDir::homePath()+"/");
451  setCurrentDir(dir);
452}
453
454void MainUI::directoryLoaded(){
455  ui->tree_dir_view->resizeColumnToContents(0);
456}
457
458void MainUI::on_tool_addToDir_clicked(){
459  bool ok = false;
460  QString newdir = QInputDialog::getText(this, tr("New Directory"), tr("Name:"), QLineEdit::Normal, "", \
461                &ok, 0, Qt::ImhFormattedNumbersOnly | Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly);
462  if(!ok || newdir.isEmpty()){ return; }
463  QString full = getCurrentDir();
464  if(!full.endsWith("/")){ full.append("/"); }
465  QDir dir(full); //open the current dir
466  full.append(newdir); //append the new name to the current dir
467  //Verify that the new dir does not already exist
468  if(dir.exists(full)){
469    QMessageBox::warning(this, tr("Invalid Name"), tr("A file or directory with that name already exists! Please pick a different name."));
470    QTimer::singleShot(0,this, SLOT(on_tool_addToDir_clicked()) ); //repeat this function
471  }else{
472    if(!dir.mkdir(newdir) ){
473      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."));
474    }
475  }
476}
477
478void MainUI::tabChanged(int tab){
479  //Load the directory contained in the new tab
480  qDebug() << "Change to Tab:" << tab << tabBar->tabText(tab);
481  QString dir = tabBar->tabWhatsThis(tab); //get the full directory
482  setCurrentDir(dir); //display this as the current dir
483}
484
485void MainUI::tabClosed(int tab){
486  if(tabBar->count()==1){ return; } //Can't close the only tab
487  if(tab < 0){ tab = tabBar->currentIndex(); }
488  //Remove the tab (will automatically move to a different one);
489  qDebug() << "Closing tab:" << tab << tabBar->tabText(tab);
490  tabBar->removeTab(tab);
491  tabBar->setVisible( tabBar->count() > 1 );
492}
493
494void MainUI::prevTab(){
495  int cur = tabBar->currentIndex();
496  if(cur == 0){ tabBar->setCurrentIndex( tabBar->count()-1 ); }
497  else{ tabBar->setCurrentIndex( cur-1 ); }
498}
499
500void MainUI::nextTab(){
501  int cur = tabBar->currentIndex();
502  if(cur == (tabBar->count()-1) ){ tabBar->setCurrentIndex(0); }
503  else{ tabBar->setCurrentIndex( cur+1 ); }     
504}
505
506void MainUI::ItemRun(const QModelIndex &index){
507  //This is called when the user double clicks a file/directory
508  QString val = fsmod->filePath(index).section("/",-1);
509  QString itemPath = getCurrentDir();
510  if( !itemPath.endsWith("/")){ itemPath.append("/"); }
511  itemPath.append(val);
512  if(fsmod->isDir(index)){
513    setCurrentDir( itemPath );
514  }else{
515    //Must be a file, try to run it
516    QProcess::startDetached("lumina-open "+itemPath);
517  }
518}
519
520void MainUI::OpenContextMenu(const QPoint &pt){
521  CItem = ui->tree_dir_view->indexAt(pt);
522  if(!CItem.isValid()){ return; }
523  //Create the context menu for this particular item
524  contextMenu->clear();
525  if(fsmod->isDir(CItem)){
526    contextMenu->addAction(LXDG::findIcon("tab-new-background",""), tr("Open in new tab"), this, SLOT(OpenDir()) );
527  }else{
528    contextMenu->addAction(LXDG::findIcon("quickopen-file",""), tr("Open"), this, SLOT(OpenItem()) );
529    contextMenu->addAction(tr("Open With..."), this, SLOT(OpenItemWith()) );
530  }
531  contextMenu->addSeparator();
532  contextMenu->addAction(LXDG::findIcon("list-remove",""), tr("Delete"), this, SLOT(RemoveItem()) );
533  contextMenu->popup(ui->tree_dir_view->mapToGlobal(pt));
534}
535
536//Slideshow Functions
537void MainUI::showNewPicture(){
538  if( !ui->label_image->isVisible() ){ return; } //don't update if not visible - can cause strange resizing issues
539  QString file = getCurrentDir();
540  if(!file.endsWith("/")){ file.append("/"); }
541  file.append(ui->combo_image_name->currentText());
542  if(!file.endsWith(".png") && !file.endsWith(".jpg")){ return; } //invalid - no change
543  //qDebug() << "Show Image:" << file;
544  QPixmap pix(file);
545  if(pix.size().width() > ui->label_image->contentsRect().width() || pix.size().height() > ui->label_image->contentsRect().height()){ 
546    pix = pix.scaled(ui->label_image->contentsRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); 
547  }
548  ui->label_image->setPixmap(pix);
549  //Now set/load the buttons
550  ui->tool_image_goBegin->setEnabled(ui->combo_image_name->currentIndex()>0);
551  ui->tool_image_goPrev->setEnabled(ui->combo_image_name->currentIndex()>0);
552  ui->tool_image_goEnd->setEnabled(ui->combo_image_name->currentIndex()<(ui->combo_image_name->count()-1));
553  ui->tool_image_goNext->setEnabled(ui->combo_image_name->currentIndex()<(ui->combo_image_name->count()-1));
554  ui->label_image_index->setText( QString::number(ui->combo_image_name->currentIndex()+1)+"/"+QString::number(ui->combo_image_name->count()) );
555}
556
557void MainUI::firstPicture(){
558  ui->combo_image_name->setCurrentIndex(0);
559}
560
561void MainUI::prevPicture(){
562  ui->combo_image_name->setCurrentIndex( ui->combo_image_name->currentIndex()-1 );
563}
564
565void MainUI::nextPicture(){
566  ui->combo_image_name->setCurrentIndex( ui->combo_image_name->currentIndex()+1 );
567}
568
569void MainUI::lastPicture(){
570  ui->combo_image_name->setCurrentIndex( ui->combo_image_name->count()-1 );
571}
572
573//ZFS Restore Functions
574void MainUI::snapshotLoaded(){
575  ui->tree_zfs_dir->resizeColumnToContents(0);
576}
577
578void MainUI::showSnapshot(){
579  ui->tool_zfs_prevSnap->setEnabled(ui->slider_zfs_snapshot->value()!=1);
580  ui->tool_zfs_nextSnap->setEnabled(ui->slider_zfs_snapshot->value()!=ui->slider_zfs_snapshot->maximum());
581  ui->label_zfs_snap->setText( snapDirs[ui->slider_zfs_snapshot->value()-1].section("/.zfs/snapshot/",1,1).section("/",0,0) );
582  //Load the dir contents
583  ui->tree_zfs_dir->setRootIndex(snapmod->setRootPath(snapDirs[ui->slider_zfs_snapshot->value()-1]));
584}
585
586void MainUI::prevSnapshot(){
587  ui->slider_zfs_snapshot->setValue(ui->slider_zfs_snapshot->value()-1);
588}
589
590void MainUI::nextSnapshot(){
591  ui->slider_zfs_snapshot->setValue(ui->slider_zfs_snapshot->value()+1);
592}
593
594void MainUI::restoreItems(){
595   //Get the selected items
596   QStringList sel;
597   QModelIndexList items = ui->tree_zfs_dir->selectionModel()->selectedIndexes();
598   for(int i=0; i<items.length(); i++){
599     sel << snapmod->filePath(items[i]).section("/",-1);
600   }
601   sel.removeDuplicates();
602   if(sel.isEmpty()){ return; } //nothing selected
603   //Get the directories
604   QString snapdir = snapDirs[ui->slider_zfs_snapshot->value()-1];
605   QString basedir = getCurrentDir();
606   if(!basedir.endsWith("/")){ basedir.append("/"); }
607   if(!snapdir.endsWith("/")){ snapdir.append("/"); }
608   //Fill out the lists appropriately
609   QStringList resto;
610   qDebug() << "Items Selected:" << sel;
611   for(int i=0; i<sel.length(); i++){
612     resto << basedir+sel[i];
613     sel[i] = snapdir+sel[i];
614   }
615   qDebug() << "Restore Items:" << sel << "\n" << resto;
616   //Restore the items
617   FODialog dlg(this);
618        dlg.setOverwrite(ui->check_zfs_overwrite->isChecked());
619        dlg.RestoreFiles(sel, resto);
620   dlg.exec();
621   if(dlg.noerrors){
622     QMessageBox::information(this, tr("Success"), tr("Successfully restored selection") );
623   }
624}
625
626// Context Menu Actions
627void MainUI::OpenItem(){
628  if(!CItem.isValid()){ return; }
629  QString fname = fsmod->fileName(CItem);
630  QString baseDir = getCurrentDir();
631  if(!baseDir.endsWith("/")){ baseDir.append("/"); }
632  baseDir.append(fname);
633  qDebug() << "Opening File:" << baseDir;
634  QProcess::startDetached("lumina-open \""+baseDir+"\"");
635}
636
637void MainUI::OpenItemWith(){
638  if(!CItem.isValid()){ return; }
639  QString fname = fsmod->fileName(CItem);
640  QString baseDir = getCurrentDir();
641  if(!baseDir.endsWith("/")){ baseDir.append("/"); }
642  baseDir.append(fname);
643  qDebug() << "Opening File:" << baseDir;
644  QProcess::startDetached("lumina-open -select \""+baseDir+"\"");       
645}
646
647void MainUI::OpenDir(){
648  if(!CItem.isValid()){ return; }
649  QString fname = fsmod->fileName(CItem);
650  QString baseDir = getCurrentDir();
651  if(!baseDir.endsWith("/")){ baseDir.append("/"); }
652  baseDir.append(fname);
653  OpenDirs(QStringList() << baseDir);           
654}
655
656void MainUI::RemoveItem(){
657   if(!isUserWritable){
658     QMessageBox::warning(this, tr("Invalid Permissions"), tr("You do not have permission to edit the files in this directory!") );
659     return;
660   }
661   //Get the selected items
662   QStringList sel, names;
663   QModelIndexList items = ui->tree_dir_view->selectionModel()->selectedIndexes();
664   QString baseDir = getCurrentDir();
665   if(!baseDir.endsWith("/")){ baseDir.append("/"); }
666   for(int i=0; i<items.length(); i++){
667     if(!names.contains(fsmod->filePath(items[i]).section("/",-1)) ){
668        names << fsmod->filePath(items[i]).section("/",-1);
669        sel << baseDir+fsmod->filePath(items[i]).section("/",-1);
670     }
671   }
672   if(sel.isEmpty()){ return; } //nothing selected
673  //Verify permanent removal of file/dir
674  if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file(s) from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+names.join("\n"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
675    return; //cancelled
676  }
677  //Now remove the file/dir
678  qDebug() << "Delete: "<<sel;
679  FODialog dlg(this);
680    dlg.RemoveFiles(sel);
681    dlg.exec();
682}
683
684void MainUI::RunInMediaPlayer(){ //open in the media player
685       
686}
687void MainUI::RunInSlideShow(){ //open in slideshow viewer
688       
689}
Note: See TracBrowser for help on using the repository browser.