source: lumina/lumina-fm/MainUI.cpp @ 08438b40

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

Clean up the directory searching and recursive removal in lumina-fm

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