void Document::renameFromKey () { if (getFileName().empty () || getKey().empty ()) return; Glib::RefPtr<Gio::File> oldfile = Gio::File::create_for_uri(getFileName()); Glib::ustring shortname = oldfile->query_info()->get_display_name(); DEBUG ("Shortname = %1", shortname); Glib::RefPtr<Gio::File> parentdir = oldfile->get_parent(); Glib::ustring::size_type pos = shortname.rfind ("."); Glib::ustring extension = ""; if (pos != Glib::ustring::npos) extension = shortname.substr (pos, shortname.length() - 1); Glib::ustring newfilename = getKey() + extension; DEBUG ("Newfilename = %1", newfilename); Glib::RefPtr<Gio::File> newfile = parentdir->get_child(newfilename); try { oldfile->move(newfile); setFileName (newfile->get_uri ()); } catch (Gio::Error &ex) { Utility::exceptionDialog (&ex, String::ucompose (_("Moving '%1' to '%2'"), oldfile->get_uri (), newfile->get_uri ()) ); } }
void _path_remove_recursive(const Glib::RefPtr<Gio::File> & dir) { Glib::RefPtr<Gio::FileEnumerator> enumerator = dir->enumerate_children(); Glib::RefPtr<Gio::FileInfo> file_info; while(file_info = enumerator->next_file()) { Glib::RefPtr<Gio::File> child; child = dir->get_child(file_info->get_name()); if(file_info->get_type() == Gio::FILE_TYPE_DIRECTORY) { _path_remove_recursive(child); } child->remove(); } }
bool StateBrush_Context::scan_directory(const String &path, int scan_sub_levels, std::set<String> &out_files) { if (scan_sub_levels < 0) return false; Glib::RefPtr<Gio::File> directory = Gio::File::create_for_path(path); Glib::RefPtr<Gio::FileEnumerator> e; try { e = directory->enumerate_children(); } catch(Gio::Error&) { return false; } catch(Glib::FileError&) { return false; } Glib::RefPtr<Gio::FileInfo> info; while((bool)(info = e->next_file())) { String filepath = FileSystem::fix_slashes(directory->get_child(info->get_name())->get_path()); if (!scan_directory(filepath, scan_sub_levels-1, out_files)) out_files.insert(filepath); } return true; }
Glib::RefPtr<PortModel> ApplicationModel::findModelFromInput(InputData* input) { for(int i=0; i<get_n_children(); i++) { // if is an application model Glib::RefPtr<ApplicationModel> application = Glib::RefPtr<ApplicationModel>::cast_dynamic(get_child(i)); if(application) { for(int k=0; k<application->get_n_children(); k++) { Glib::RefPtr<ModuleModel> module = Glib::RefPtr<ModuleModel>::cast_dynamic(application->get_child(k)); if(module) { for(int j=0; j<module->get_n_children(); j++) { Glib::RefPtr<InternalPortModel> intPort = Glib::RefPtr<InternalPortModel>::cast_dynamic(module->get_child(j)); if(intPort && (intPort->getInput() == input)) return intPort; } } } } Glib::RefPtr<ModuleModel> module = Glib::RefPtr<ModuleModel>::cast_dynamic(get_child(i)); if(module) { for(int j=0; j<get_child(i)->get_n_children(); j++) { Glib::RefPtr<InternalPortModel> intPort = Glib::RefPtr<InternalPortModel>::cast_dynamic(get_child(i)->get_child(j)); if(intPort && (intPort->getInput() == input)) return intPort; } } } return Glib::RefPtr<PortModel>(NULL); }