diff options
-rw-r--r-- | lumina-fm/BackgroundWorker.cpp | 20 | ||||
-rw-r--r-- | lumina-fm/BackgroundWorker.h | 1 | ||||
-rw-r--r-- | lumina-fm/FODialog.cpp | 206 | ||||
-rw-r--r-- | lumina-fm/FODialog.h | 46 | ||||
-rw-r--r-- | lumina-fm/MainUI.cpp | 43 | ||||
-rw-r--r-- | lumina-fm/MainUI.h | 3 |
6 files changed, 225 insertions, 94 deletions
diff --git a/lumina-fm/BackgroundWorker.cpp b/lumina-fm/BackgroundWorker.cpp index 9b3804d5..bbba8749 100644 --- a/lumina-fm/BackgroundWorker.cpp +++ b/lumina-fm/BackgroundWorker.cpp @@ -37,19 +37,27 @@ void BackgroundWorker::startDirChecks(QString path){ //Now check for ZFS snapshots of the directory if(!QFileInfo(path).isWritable() ){ return; } //skip ZFS checks if can't restore to this dir + cdir = path; QStringList snapDirs; QString baseSnapDir; bool found = false; - while(dir.absolutePath()!="/" && !found){ - if(dir.exists(".zfs/snapshot")){ found = true;} - else{ dir.cdUp(); } + if(cdir == path && QFile::exists(csnapdir) ){ + //no need to re-search for it - just found it recently + baseSnapDir= csnapdir; found=true; + }else{ + while(dir.absolutePath()!="/" && !found){ + if(dir.exists(".zfs/snapshot")){ + baseSnapDir = dir.canonicalPath()+"/.zfs/snapshot"; + found = true; + }else{ dir.cdUp(); } + } } + cdir = path; csnapdir = baseSnapDir; //Now find the snapshots that contain this directory and save them if(found){ QString reldir = path; - reldir.remove(dir.absolutePath()); //convert to a relative path - dir.cd(".zfs/snapshot"); - baseSnapDir = dir.canonicalPath(); //set the base snapshot dir as the new root + reldir.remove(baseSnapDir.section("/.zfs/snapshot",0,0)); //convert to a relative path + dir.cd(baseSnapDir); snapDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); //Check that the current directory exists in each snapshot for(int i=0; i<snapDirs.length(); i++){ diff --git a/lumina-fm/BackgroundWorker.h b/lumina-fm/BackgroundWorker.h index 3f0410bf..25becb53 100644 --- a/lumina-fm/BackgroundWorker.h +++ b/lumina-fm/BackgroundWorker.h @@ -25,6 +25,7 @@ public: private: QStringList multiFilter, imgFilter; + QString cdir, csnapdir; //last directory checked (and base snapshot dir found) public slots: //Kickoff processes with these slots diff --git a/lumina-fm/FODialog.cpp b/lumina-fm/FODialog.cpp index 1ba27896..e10b825e 100644 --- a/lumina-fm/FODialog.cpp +++ b/lumina-fm/FODialog.cpp @@ -8,63 +8,154 @@ #include "ui_FODialog.h" #include <QApplication> +#include <QFontMetrics> FODialog::FODialog(QWidget *parent) : QDialog(parent), ui(new Ui::FODialog){ ui->setupUi(this); //load the designer file ui->label->setText(tr("Calculating")); ui->progressBar->setVisible(false); ui->push_stop->setIcon( LXDG::findIcon("edit-delete","") ); - //Now set the internal defaults - isRM = isCP = isRESTORE = isMV = stopped = noerrors = false; - overwrite = -1; //set to automatic by default + WorkThread = new QThread(); + Worker = new FOWorker(); + connect(Worker, SIGNAL(startingItem(int,int,QString,QString)), this, SLOT(UpdateItem(int,int,QString,QString)) ); + connect(Worker, SIGNAL(finished(QStringList)), this, SLOT(WorkDone(QStringList)) ); + Worker->moveToThread(WorkThread); + WorkThread->start(); + + //Make sure this dialog is centered on the parent + if(parent!=0){ + QPoint ctr = parent->geometry().center(); + this->move( ctr.x()-(this->width()/2), ctr.y()-(this->height()/2) ); + } this->show(); } FODialog::~FODialog(){ - stopped = true; //just in case it might still be running when closed + Worker->stopped = true; //just in case it might still be running when closed + WorkThread->quit(); + WorkThread->wait(); + delete Worker; + //delete WorkThread; } void FODialog::setOverwrite(bool ovw){ - if(ovw){ overwrite = 1; } - else{ overwrite = 0; } + if(ovw){ Worker->overwrite = 1; } + else{ Worker->overwrite = 0; } } //Public "start" functions void FODialog::RemoveFiles(QStringList paths){ - ofiles = paths; - isRM = true; - QTimer::singleShot(10,this, SLOT(slotStartOperations())); + Worker->ofiles = paths; + Worker->isRM = true; + if(CheckOverwrite()){ + QTimer::singleShot(10,Worker, SLOT(slotStartOperations())); + }else{ + this->close(); + } } void FODialog::CopyFiles(QStringList oldPaths, QStringList newPaths){ //same permissions as old files if(oldPaths.length() == newPaths.length()){ - ofiles = oldPaths; nfiles = newPaths; + Worker->ofiles = oldPaths; + Worker->nfiles = newPaths; + } + Worker->isCP=true; + if(CheckOverwrite()){ + QTimer::singleShot(10,Worker, SLOT(slotStartOperations())); + }else{ + this->close(); } - isCP=true; - QTimer::singleShot(10,this, SLOT(slotStartOperations())); } void FODialog::RestoreFiles(QStringList oldPaths, QStringList newPaths){ //user/group rw permissions if(oldPaths.length() == newPaths.length()){ - ofiles = oldPaths; nfiles = newPaths; + Worker->ofiles = oldPaths; + Worker->nfiles = newPaths; + } + Worker->isRESTORE = true; + if(CheckOverwrite()){ + QTimer::singleShot(10,Worker, SLOT(slotStartOperations())); + }else{ + this->close(); } - isRESTORE = true; - QTimer::singleShot(10,this, SLOT(slotStartOperations())); } void FODialog::MoveFiles(QStringList oldPaths, QStringList newPaths){ //no change in permissions if(oldPaths.length() == newPaths.length()){ - ofiles = oldPaths; nfiles = newPaths; + Worker->ofiles = oldPaths; \ + Worker->nfiles = newPaths; + } + Worker->isMV=true; + if(CheckOverwrite()){ + QTimer::singleShot(10,Worker, SLOT(slotStartOperations())); + }else{ + this->close(); } - isMV=true; - QTimer::singleShot(10,this, SLOT(slotStartOperations())); } -// ==== PRIVATE ==== -QStringList FODialog::subfiles(QString dirpath, bool dirsfirst){ +bool FODialog::CheckOverwrite(){ + bool ok = true; + if(!Worker->isRM && Worker->overwrite==-1){ + //Check if the new files already exist, and prompt for action + QStringList existing; + for(int i=0; i<Worker->nfiles.length(); i++){ + if(QFile::exists(Worker->nfiles[i])){ existing << Worker->nfiles[i].section("/",-1); } + } + if(!existing.isEmpty()){ + //Prompt for whether to overwrite, not overwrite, or cancel + QMessageBox::StandardButton ans = QMessageBox::question(this, tr("Overwrite Files?"), tr("Do you want to overwrite the existing files?")+"\n"+tr("Note: It will just add a number to the filename otherwise.")+"\n\n"+existing.join(", "), QMessageBox::YesToAll | QMessageBox::NoToAll | QMessageBox::Cancel, QMessageBox::NoToAll); + if(ans==QMessageBox::NoToAll){ Worker->overwrite = 0; } //don't overwrite + else if(ans==QMessageBox::YesToAll){ Worker->overwrite = 1; } //overwrite + else{ ok = false; } //cancel operations + } + } + return ok; +} + +void FODialog::UpdateItem(int cur, int tot, QString oitem, QString nitem){ + ui->progressBar->setRange(0,tot); + ui->progressBar->setValue(cur); + ui->progressBar->setVisible(true); + QString msg; + if(Worker->isRM){ msg = tr("Removing: %1"); } + else if(Worker->isCP){ msg = tr("Copying: %1 to %2"); } + else if(Worker->isRESTORE){ msg = tr("Restoring: %1 as %2"); } + else if(Worker->isMV){ msg = tr("Moving: %1 to %2"); } + if(msg.contains("%2")){ + msg = msg.arg(oitem.section("/",-1), nitem.section("/",-1)); + }else{ + msg = msg.arg(oitem.section("/",-1)); + } + msg = ui->label->fontMetrics().elidedText(msg, Qt::ElideRight, ui->label->width()); + ui->label->setText( msg ); + //this->repaint(); + QApplication::processEvents( QEventLoop::ExcludeUserInputEvents ); +} + +void FODialog::WorkDone(QStringList errlist){ + if(!errlist.isEmpty()){ + QString msg; + if(Worker->isRM){ msg = tr("Could not remove these files:"); } + else if(Worker->isCP){ msg = tr("Could not copy these files:"); } + else if(Worker->isRESTORE){ msg = tr("Could not restore these files:"); } + else if(Worker->isMV){ msg = tr("Could not move these files:"); } + QMessageBox::warning(this, tr("File Errors"), msg+"\n\n"+errlist.join("\n")); + } + noerrors = errlist.isEmpty(); + this->close(); +} + +void FODialog::on_push_stop_clicked(){ + Worker->stopped = true; +} + +// =================== +// ==== FOWorker Class ==== +// =================== +QStringList FOWorker::subfiles(QString dirpath, bool dirsfirst){ //NOTE: dirpath (input) is always the first/last item in the output as well! QStringList out; if(dirsfirst){ out << dirpath; } @@ -89,7 +180,7 @@ QStringList FODialog::subfiles(QString dirpath, bool dirsfirst){ return out; } -QString FODialog::newFileName(QString path){ +QString FOWorker::newFileName(QString path){ int num=1; QString extension = path.section("/",-1).section(".",-1); if( path.section("/",-1) == "."+extension || extension ==path.section("/",-1) ){ extension.clear(); } //just a hidden file without extension or directory @@ -101,7 +192,7 @@ QString FODialog::newFileName(QString path){ return QString(path+"-"+QString::number(num)+extension); } -QStringList FODialog::removeItem(QString path, bool recursive){ +QStringList FOWorker::removeItem(QString path, bool recursive){ //qDebug() << "Remove Path:" << path; QStringList items; if(recursive){ items = subfiles(path,false); } @@ -126,7 +217,7 @@ QStringList FODialog::removeItem(QString path, bool recursive){ return err; } -QStringList FODialog::copyItem(QString oldpath, QString newpath){ +QStringList FOWorker::copyItem(QString oldpath, QString newpath){ QStringList err; if(QFileInfo(oldpath).isDir()){ //Create a new directory with the same name (no way to copy dir+contents) @@ -149,15 +240,14 @@ QStringList FODialog::copyItem(QString oldpath, QString newpath){ } // ==== PRIVATE SLOTS ==== -void FODialog::slotStartOperations(){ - ui->label->setText(tr("Calculating...")); +void FOWorker::slotStartOperations(){ //qDebug() << "Start File operations" << isRM << isCP << isMV << ofiles << nfiles; //Now setup the UI - ui->progressBar->setRange(0,ofiles.length()); + /*ui->progressBar->setRange(0,ofiles.length()); ui->progressBar->setValue(0); ui->progressBar->setVisible(true); - QApplication::processEvents(); - if(!isRM && overwrite==-1){ + QApplication::processEvents();*/ + /*if(!isRM && overwrite==-1){ //Check if the new files already exist, and prompt for action QStringList existing; for(int i=0; i<nfiles.length(); i++){ @@ -168,12 +258,13 @@ void FODialog::slotStartOperations(){ QMessageBox::StandardButton ans = QMessageBox::question(this, tr("Overwrite Files?"), tr("Do you want to overwrite the existing files?")+"\n"+tr("Note: It will just add a number to the filename otherwise.")+"\n\n"+existing.join(", "), QMessageBox::YesToAll | QMessageBox::NoToAll | QMessageBox::Cancel, QMessageBox::NoToAll); if(ans==QMessageBox::NoToAll){ overwrite = 0; } //don't overwrite else if(ans==QMessageBox::YesToAll){ overwrite = 1; } //overwrite - else{ this->close(); return; } //cancel operations + else{ emit finished(QStringList()); return; } //cancel operations } - } + }*/ + //Get the complete number of items to be operated on (better tracking) - QStringList olist, nlist; //old/new list - for(int i=0; i<ofiles.length(); i++){ + QStringList olist, nlist; //old/new list to actually be used (not inputs - modified/added as necessary) + for(int i=0; i<ofiles.length() && !stopped; i++){ if(isRM){ //only old files olist << subfiles(ofiles[i], false); //dirs need to be last for removals }else if(isCP || isRESTORE){ @@ -193,7 +284,8 @@ void FODialog::slotStartOperations(){ if( nfiles[i].startsWith(ofiles[i]+"/") ){ //This is trying to move a directory into itself (not possible) // Example: move "~/mydir" -> "~/mydir/mydir2" - QMessageBox::warning(this, tr("Invalid Move"), QString(tr("It is not possible to move a directory into itself. Please make a copy of the directory instead.\n\nOld Location: %1\nNew Location: %2")).arg(ofiles[i], nfiles[i]) ); + QStringList err; err << tr("Invalid Move") << QString(tr("It is not possible to move a directory into itself. Please make a copy of the directory instead.\n\nOld Location: %1\nNew Location: %2")).arg(ofiles[i], nfiles[i]); + emit finished(err); return; }else{ //no changes necessary olist << ofiles[i]; @@ -205,56 +297,36 @@ void FODialog::slotStartOperations(){ QStringList errlist; for(int i=0; i<olist.length() && !stopped; i++){ if(isRM){ - ui->label->setText( QString(tr("Removing: %1")).arg(olist[i].section("/",-1)) ); - QApplication::processEvents(); + /*ui->label->setText( QString(tr("Removing: %1")).arg(olist[i].section("/",-1)) ); + QApplication::processEvents();*/ + emit startingItem(i+1,olist.length(), olist[i], ""); errlist << removeItem(olist[i]); }else if(isCP || isRESTORE){ - ui->label->setText( QString(tr("Copying: %1 to %2")).arg(olist[i].section("/",-1), nlist[i].section("/",-1)) ); - QApplication::processEvents(); + /*ui->label->setText( QString(tr("Copying: %1 to %2")).arg(olist[i].section("/",-1), nlist[i].section("/",-1)) ); + QApplication::processEvents();*/ + emit startingItem(i+1,olist.length(), olist[i],nlist[i]); if(QFile::exists(nlist[i])){ if(overwrite){ errlist << removeItem(nlist[i], true); //recursively remove the file/dir since we are supposed to overwrite it } } //If a parent directory fails to copy, skip all the children as well (they will also fail) - QApplication::processEvents(); + //QApplication::processEvents(); if( !errlist.contains(olist[i].section("/",0,-1)) ){ errlist << copyItem(olist[i], nlist[i]); } - /*if(err.isEmpty() && !subs.isEmpty() ){ //make sure the initial parent dir did not error out - //For copies of directories, also need to copy over all the sub files/dirs - for(int s=0; s<subs.length(); s++){ - //Replace the old parent directory path with the new parent directory path; - QString newsub = subs[s].section(ofiles[i],0,100, QString::SectionSkipEmpty); - newsub.prepend(nfiles[i]); - //qDebug() << "Copy Sub:" << subs[s] << newsub; - errlist << copyItem(subs[s], newsub); - } - }*/ }else if(isMV){ - ui->label->setText( QString(tr("Moving: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); - QApplication::processEvents(); + /*ui->label->setText( QString(tr("Moving: %1 to %2")).arg(ofiles[i].section("/",-1), nfiles[i].section("/",-1)) ); + QApplication::processEvents();*/ + emit startingItem(i+1,olist.length(), olist[i], nlist[i]); if( !QFile::rename(ofiles[i], nfiles[i]) ){ errlist << ofiles[i]; } } - ui->progressBar->setValue(i+1); - QApplication::processEvents(); + //ui->progressBar->setValue(i+1); + //QApplication::processEvents(); } - //All finished, so close the dialog if successful + //All finished, emit the signal errlist.removeAll(""); //make sure to clear any empty items - if(!errlist.isEmpty()){ - QString msg; - if(isRM){ msg = tr("Could not remove these files:"); } - else if(isCP){ msg = tr("Could not copy these files:"); } - else if(isRESTORE){ msg = tr("Could not restore these files:"); } - else if(isMV){ msg = tr("Could not move these files:"); } - QMessageBox::warning(this, tr("File Errors"), msg+"\n\n"+errlist.join("\n")); - } - noerrors = errlist.isEmpty(); - this->close(); + emit finished(errlist); } - -void FODialog::on_push_stop_clicked(){ - stopped = true; -}
\ No newline at end of file diff --git a/lumina-fm/FODialog.h b/lumina-fm/FODialog.h index e455c995..005e6d01 100644 --- a/lumina-fm/FODialog.h +++ b/lumina-fm/FODialog.h @@ -17,6 +17,7 @@ #include <QFileInfo> #include <QDir> #include <QFile> +#include <QThread> // libLumina includes #include <LuminaXDG.h> @@ -26,6 +27,37 @@ namespace Ui{ class FODialog; }; +class FOWorker : public QObject{ + Q_OBJECT +public: + //variables that need to be set before starting the operations + QStringList ofiles, nfiles; //original/new files + bool isRM, isCP, isRESTORE, isMV; + bool stopped; + int overwrite; // [-1= auto, 0= no overwrite, 1= overwrite] + + + FOWorker() : QObject(){ + isRM = isCP = isRESTORE = isMV = stopped = false; + overwrite = -1; //auto + } + ~FOWorker(){} + +public slots: + void slotStartOperations(); + +private: + + QStringList subfiles(QString dirpath, bool dirsfirst = false); //recursive function for fetching all "child" files/dirs (dirs last by default) + QString newFileName(QString path); + QStringList removeItem(QString path, bool recursive = false); + QStringList copyItem(QString oldpath, QString newpath); + +signals: + void startingItem(int, int, QString, QString); //current number, total number, Old File, New File (if appropriate) + void finished(QStringList); //errors returned +}; + class FODialog : public QDialog{ Q_OBJECT public: @@ -42,19 +74,15 @@ public: private: Ui::FODialog *ui; - bool isRM, isCP, isRESTORE, isMV; - bool stopped; - int overwrite; // [-1= auto, 0= no overwrite, 1= overwrite] - QStringList ofiles, nfiles; //original/new files + QThread *WorkThread; + FOWorker *Worker; - QStringList subfiles(QString dirpath, bool dirsfirst = false); //recursive function for fetching all "child" files/dirs (dirs last by default) - QString newFileName(QString path); - QStringList removeItem(QString path, bool recursive = false); - QStringList copyItem(QString oldpath, QString newpath); + bool CheckOverwrite(); //Returns "true" if it is ok to start the procedure private slots: - void slotStartOperations(); void on_push_stop_clicked(); + void UpdateItem(int, int, QString, QString); + void WorkDone(QStringList); }; #endif diff --git a/lumina-fm/MainUI.cpp b/lumina-fm/MainUI.cpp index 7a10d41e..66a0cab2 100644 --- a/lumina-fm/MainUI.cpp +++ b/lumina-fm/MainUI.cpp @@ -9,18 +9,26 @@ #include <QImageWriter> +#define DEBUG 1 + MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); + if(DEBUG){ qDebug() << "Initilization:"; } //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 + syncTimer = new QTimer(this); + syncTimer->setInterval(200); //1/5 second (collect as many signals/slots as necessary + syncTimer->setSingleShot(true); //Reset the UI to the previously used size (if possible) + if(DEBUG){ qDebug() << " - Reset window size"; } 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 + if(DEBUG){ qDebug() << " - Tab Bar Setup"; } tabBar = new QTabBar(this); tabBar->setTabsClosable(true); tabBar->setMovable(true); //tabs are independant - so allow the user to sort them @@ -30,12 +38,12 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ currentDir = new QLineEdit(this); ui->toolBar->insertWidget(ui->actionBookMark, currentDir); currentDir->setFocusPolicy(Qt::StrongFocus); - + if(DEBUG){ qDebug() << " - Threading"; } workThread = new QThread; workThread->setObjectName("Lumina-fm filesystem worker"); worker = new BackgroundWorker; worker->moveToThread(workThread); - + if(DEBUG){ qDebug() << " - File System Model"; } fsmod = new QFileSystemModel(this); fsmod->setRootPath("/"); ui->tree_dir_view->setModel(fsmod); @@ -50,9 +58,11 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ snapmod = new QFileSystemModel(this); ui->tree_zfs_dir->setModel(snapmod); ui->tree_zfs_dir->sortByColumn(0, Qt::AscendingOrder); + if(DEBUG){ qDebug() << " - Icon Provider"; } iconProv = new MimeIconProvider(); fsmod->setIconProvider(iconProv); snapmod->setIconProvider(iconProv); + if(DEBUG){ qDebug() << " - Context Menu"; } contextMenu = new QMenu(this); radio_view_details = new QRadioButton(tr("Detailed List"), this); radio_view_list = new QRadioButton(tr("Basic List"), this); @@ -67,6 +77,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->menuView->addAction(listWA); ui->menuView->addAction(icoWA); //Setup the special Phonon widgets + if(DEBUG){ qDebug() << " - Multimedia Widgets"; } mediaObj = new QMediaPlayer(this); mediaObj->setVolume(100); mediaObj->setNotifyInterval(500); //only every 1/2 second update @@ -82,6 +93,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->tool_player_pause->setVisible(false); //nothing to pause yet playerSlider->setEnabled(false); //nothing to seek yet //Setup any specialty keyboard shortcuts + if(DEBUG){ qDebug() << " - 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); @@ -90,13 +102,20 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ deleteFilesShort = new QShortcut( QKeySequence(tr("Delete")), this); //Finish loading the interface workThread->start(); + if(DEBUG){ qDebug() << " - Icons"; } setupIcons(); + if(DEBUG){ qDebug() << " - Connections"; } setupConnections(); + if(DEBUG){ qDebug() << " - Settings"; } loadSettings(); + if(DEBUG){ qDebug() << " - Bookmarks"; } RebuildBookmarksMenu(); + if(DEBUG){ qDebug() << " - Devices"; } RebuildDeviceMenu(); //Make sure we start on the browser page + if(DEBUG){ qDebug() << " - Load Browser Page"; } goToBrowserPage(); + if(DEBUG){ qDebug() << " - Done with init"; } } MainUI::~MainUI(){ @@ -110,7 +129,7 @@ void MainUI::OpenDirs(QStringList dirs){ //Add this directory in a new tab if(dirs[i].endsWith("/")){ dirs[i].chop(1); } if(!QFile::exists(dirs[i])){ invalid << dirs[i]; continue; } - qDebug() << "Open Directory:" << dirs[i]; + if(DEBUG){ qDebug() << "Open Directory:" << dirs[i]; } int index = tabBar->addTab( dirs[i].section("/",-1) ); tabBar->setTabWhatsThis( index, dirs[i] ); if(index==0){ setCurrentDir(dirs[i]); }//display this as the current dir @@ -185,8 +204,8 @@ void MainUI::setupConnections(){ 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)) ); - connect(fsmod, SIGNAL(directoryLoaded(QString)), this, SLOT(currentDirectoryLoaded()) ); - + connect(fsmod, SIGNAL(directoryLoaded(QString)), this, SLOT(slotStartSyncTimer()) ); + connect(syncTimer, SIGNAL(timeout()), this, SLOT(currentDirectoryLoaded()) ); //Background worker class connect(this, SIGNAL(DirChanged(QString)), worker, SLOT(startDirChecks(QString)) ); connect(worker, SIGNAL(ImagesAvailable(QStringList)), this, SLOT(AvailablePictures(QStringList)) ); @@ -374,6 +393,7 @@ QString MainUI::getCurrentDir(){ void MainUI::setCurrentDir(QString dir){ if(dir.isEmpty()){ return; } + if(syncTimer->isActive()){ syncTimer->stop(); } //already loading the info QFileInfo info(dir); QString olddir = currentDir->whatsThis(); if(!info.isDir() || !info.exists() ){ @@ -452,6 +472,12 @@ QFileInfoList MainUI::getSelectedItems(){ //============== // PRIVATE SLOTS //============== +void MainUI::slotStartSyncTimer(){ + if(ui->stackedWidget->currentWidget()!=ui->page_browser){ return; } + if(syncTimer->isActive()){ syncTimer->stop(); } + syncTimer->start(); +} + //General button check functions void MainUI::AvailableMultimediaFiles(QStringList files){ if(!files.isEmpty()){ @@ -921,14 +947,7 @@ void MainUI::removePicture(){ file.append(ui->combo_image_name->currentText()); if( QFile::remove(file) ){ int index = ui->combo_image_name->currentIndex(); - int newindex = index; - newindex--; ui->combo_image_name->removeItem( index ); - //showNewPicture(); - //Move to the new index before removing the old one - /*if(newindex>=0){ - ui->combo_image_name->setCurrentIndex(newindex); - }*/ } } diff --git a/lumina-fm/MainUI.h b/lumina-fm/MainUI.h index 9dab45ed..ccc85f72 100644 --- a/lumina-fm/MainUI.h +++ b/lumina-fm/MainUI.h @@ -99,6 +99,7 @@ private: QShortcut *nextTabLShort, *nextTabRShort, *closeTabShort, *copyFilesShort, *pasteFilesShort, *deleteFilesShort; QCompleter *dirCompleter; bool isUserWritable, keepFocus; + QTimer *syncTimer; //Simplification Functions void setupConnections(); //used during initialization @@ -122,6 +123,8 @@ private slots: this->OpenDirs(in); } + void slotStartSyncTimer(); + //General button check functions (started in a seperate thread!) void AvailableMultimediaFiles(QStringList files); void AvailableBackups(QString basedir, QStringList snapdirs); |