From 550a8685312877ee8994cb088cb4f0a0df5d562d Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 12 Feb 2011 22:37:55 -0500 Subject: [PATCH] File Browser - copy and move files (issue 532) --- rtdata/languages/default | 2 + rtgui/filebrowser.cc | 12 ++++++ rtgui/filebrowser.h | 3 ++ rtgui/filecatalog.cc | 85 ++++++++++++++++++++++++++++++++++++++++ rtgui/filecatalog.h | 1 + 5 files changed, 103 insertions(+) diff --git a/rtdata/languages/default b/rtdata/languages/default index a16d0057c..fff78e3c8 100644 --- a/rtdata/languages/default +++ b/rtdata/languages/default @@ -80,6 +80,8 @@ FILEBROWSER_NEW_NAME;New name: FILEBROWSER_PARTIALPASTEPROFILE;Partial paste FILEBROWSER_PASTEPROFILE;Paste profile FILEBROWSER_POPUPCANCELJOB;Cancel job +FILEBROWSER_POPUPCOPYTO;Copy to... +FILEBROWSER_POPUPMOVETO;Move to... FILEBROWSER_POPUPMOVEEND;Move to end of queue FILEBROWSER_POPUPMOVEHEAD;Move to head of queue FILEBROWSER_POPUPOPEN;Open diff --git a/rtgui/filebrowser.cc b/rtgui/filebrowser.cc index 9bbeb5ac2..d805fffc2 100644 --- a/rtgui/filebrowser.cc +++ b/rtgui/filebrowser.cc @@ -62,6 +62,8 @@ FileBrowser::FileBrowser () pmenu->attach (*(removeInclProc = new Gtk::MenuItem (M("FILEBROWSER_POPUPREMOVEINCLPROC"))), 0, 1, p, p+1); p++; pmenu->attach (*(new Gtk::SeparatorMenuItem ()), 0, 1, p, p+1); p++; pmenu->attach (*(selall = new Gtk::MenuItem (M("FILEBROWSER_POPUPSELECTALL"))), 0, 1, p, p+1); p++; + pmenu->attach (*(copyTo = new Gtk::MenuItem (M("FILEBROWSER_POPUPCOPYTO"))), 0, 1, p, p+1); p++; + pmenu->attach (*(moveTo = new Gtk::MenuItem (M("FILEBROWSER_POPUPMOVETO"))), 0, 1, p, p+1); p++; pmenu->attach (*(new Gtk::SeparatorMenuItem ()), 0, 1, p, p+1); p++; pmenu->attach (*(menuDF = new Gtk::MenuItem (M("FILEBROWSER_DARKFRAME"))), 0, 1, p, p+1); p++; pmenu->attach (*(menuFF = new Gtk::MenuItem (M("FILEBROWSER_FLATFIELD"))), 0, 1, p, p+1); p++; @@ -97,6 +99,8 @@ FileBrowser::FileBrowser () remove->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), remove)); removeInclProc->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), removeInclProc)); selall->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), selall)); + copyTo->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), copyTo)); + moveTo->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), moveTo)); copyprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), copyprof)); pasteprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), pasteprof)); partpasteprof->signal_activate().connect (sigc::bind(sigc::mem_fun(*this, &FileBrowser::menuItemActivated), partpasteprof)); @@ -337,6 +341,14 @@ void FileBrowser::menuItemActivated (Gtk::MenuItem* m) { queue_draw (); notifySelectionListener (); } + else if( m==copyTo){ + tbl->copyMoveRequested (mselected, false); + } + + else if( m==moveTo){ + tbl->copyMoveRequested (mselected, true); + } + else if (m==autoDF){ for (int i=0; ithumbnail->getProcParams(); diff --git a/rtgui/filebrowser.h b/rtgui/filebrowser.h index a2efb3fcc..328e5d37b 100644 --- a/rtgui/filebrowser.h +++ b/rtgui/filebrowser.h @@ -35,6 +35,7 @@ class FileBrowserListener { virtual void developRequested (std::vector tbe) {} virtual void renameRequested (std::vector tbe) {} virtual void deleteRequested (std::vector tbe, bool inclBatchProcessed) {} + virtual void copyMoveRequested (std::vector tbe, bool moveRequested) {} virtual void selectionChanged (std::vector tbe) {} virtual void clearFromCacheRequested(std::vector tbe, bool leavenotrace) {} }; @@ -60,6 +61,8 @@ class FileBrowser : public ThumbBrowserBase, public LWButtonListener { Gtk::MenuItem* removeInclProc; Gtk::MenuItem* open; Gtk::MenuItem* selall; + Gtk::MenuItem* copyTo; + Gtk::MenuItem* moveTo; Gtk::MenuItem* menuDF; Gtk::MenuItem* selectDF; diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index cf57c1464..5b829b879 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -553,6 +553,91 @@ void FileCatalog::deleteRequested (std::vector tbe, bool inc } } + +void FileCatalog::copyMoveRequested (std::vector tbe, bool moveRequested) { + + if (tbe.size()==0) + return; + + Gtk::FileChooserDialog fc(M("FILEBROWSER_POPUPMOVETO"),Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER ); + fc.add_button( Gtk::StockID("gtk-cancel"), Gtk::RESPONSE_CANCEL); + fc.add_button( Gtk::StockID("gtk-ok"), Gtk::RESPONSE_OK); + // open dialog at the 1-st file's path + fc.set_filename(tbe[0]->filename); + //!!! TOFO prevent dialog closing on "enter" key press + + bool filecopymovecomplete; + int i_copyindex; + + if( fc.run() == Gtk::RESPONSE_OK ){ + Glib::ustring dest_Dir = fc.get_current_folder(); + + // iterate through selected files + for (unsigned int i=0; ifilename; + Glib::ustring src_Dir = Glib::path_get_dirname(src_fPath); + Glib::RefPtr file = Gio::File::create_for_path ( src_fPath ); + if( !file ) continue; // if file is missing - skip it + + Glib::ustring fname=file->get_basename(); + Glib::ustring fname_noExt = removeExtension(fname); + Glib::ustring fname_Ext = getExtension(fname); + + // construct destinations File Paths + Glib::ustring destfPath = dest_Dir + "/" + fname; + Glib::ustring destfPath_param= destfPath + paramFileExtension; + + if (moveRequested && (src_Dir==dest_Dir)) continue; + /* comparison of src_Dir and dest_Dir is done per image for compatibility with + possible future use of Collections as source where each file's source path may be different.*/ + + filecopymovecomplete = false; + i_copyindex = 1; + while(!filecopymovecomplete){ // should we limit the number of iteration attempts here? (i_copyindex<100)? + if (!safe_file_test(destfPath, Glib::FILE_TEST_EXISTS) && !safe_file_test(destfPath_param, Glib::FILE_TEST_EXISTS)){ + // copy/move file to destination + Glib::RefPtr dest_file = Gio::File::create_for_path ( destfPath ); + if (moveRequested) { + // remove from browser + FileBrowserEntry* t = fileBrowser->delEntry (src_fPath); + // remove from cache + // !!! this could be optimized to re-attach cache files and avoid their regeneration + cacheMgr->deleteEntry (src_fPath); + // move file + file->move(dest_file); + } + else + file->copy(dest_file); + + // attempt to copy/move paramFile only if it exist + Glib::RefPtr file_param = Gio::File::create_for_path ( src_fPath + paramFileExtension ); + if (safe_file_test( src_fPath + paramFileExtension, Glib::FILE_TEST_EXISTS)){ + Glib::RefPtr dest_param = Gio::File::create_for_path ( destfPath_param); + // copy/move paramFile to destination + if (moveRequested){ + /* comparison of src_fPath and destfPath is done per image for a compatibility with + possible future use with collections where each file's source path may be different.*/ + file_param->move(dest_param); + } + else + file_param->copy(dest_param); + } + + filecopymovecomplete = true; + } + else{ + // adjust destination fname to avoid conflicts (append "_", preserve extension) + fname = Glib::ustring::compose("%1%2%3%4%5",fname_noExt,"_",i_copyindex,".",fname_Ext); + // re-construct destination File Paths + destfPath = dest_Dir + "/" + fname; + destfPath_param= destfPath + paramFileExtension; + i_copyindex++; + } + }//while + } // i tbe) { if (listener) { diff --git a/rtgui/filecatalog.h b/rtgui/filecatalog.h index b9c295761..90076e7c0 100644 --- a/rtgui/filecatalog.h +++ b/rtgui/filecatalog.h @@ -162,6 +162,7 @@ class FileCatalog : public Gtk::VBox, void openRequested (std::vector tbe); void deleteRequested (std::vector tbe, bool inclBatchProcessed); + void copyMoveRequested (std::vector tbe, bool moveRequested); void developRequested (std::vector tbe); void renameRequested (std::vector tbe); void clearFromCacheRequested(std::vector tbe, bool leavenotrace);