bool Launcher::openFolder(GAppLaunchContext* ctx, GList* folder_infos, GError** err) { GList* l = folder_infos; FmFileInfo* fi = FM_FILE_INFO(l->data); Application* app = static_cast<Application*>(qApp); MainWindow* mainWindow = mainWindow_; Fm::FilePath path{fm_path_to_gfile(fm_file_info_get_path(fi)), false}; if(!mainWindow) { mainWindow = new MainWindow(std::move(path)); mainWindow->resize(app->settings().windowWidth(), app->settings().windowHeight()); if(app->settings().windowMaximized()) { mainWindow->setWindowState(mainWindow->windowState() | Qt::WindowMaximized); } } else { mainWindow->chdir(std::move(path)); } l = l->next; for(; l; l = l->next) { fi = FM_FILE_INFO(l->data); path = Fm::FilePath{fm_path_to_gfile(fm_file_info_get_path(fi)), false}; mainWindow->addTab(std::move(path)); } mainWindow->show(); mainWindow->raise(); return true; }
gint sort(FmFileInfo *fi1, FmFileInfo *fi2){ char *filename1, *filename2; int year1 = 0, year2 = 0; TagLib_File *TL_file1, *TL_file2; filename1 = fm_path_to_str( fm_file_info_get_path(fi1) ); filename2 = fm_path_to_str( fm_file_info_get_path(fi2) ); TL_file1 = taglib_file_new( filename1 ); TL_file2 = taglib_file_new( filename2 ); free( filename1 ); free( filename2 ); if (TL_file1 != NULL) { if(taglib_file_is_valid(TL_file1)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file1 ); year1 = taglib_tag_year( TL_tag ); taglib_tag_free_strings(); taglib_file_free( TL_file1 ); } } if (TL_file2 != NULL) { if(taglib_file_is_valid(TL_file2)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file2 ); year2 = taglib_tag_year( TL_tag ); taglib_tag_free_strings(); taglib_file_free( TL_file2 ); } } return year1 - year2; }
static gboolean open_folder_func(GAppLaunchContext* ctx, GList* folder_infos, gpointer user_data, GError** err) { FmMainWin* win = FM_MAIN_WIN(user_data); GList* l = folder_infos; FmFileInfo* fi = (FmFileInfo*)l->data; fm_main_win_chdir(win, fm_file_info_get_path(fi), NULL); l=l->next; for(; l; l=l->next) { FmFileInfo* fi = (FmFileInfo*)l->data; fm_main_win_add_tab(win, fm_file_info_get_path(fi)); } return TRUE; }
static void fm_dir_tree_model_add_place_holder_child_item (FmDirTreeModel *dir_tree_model, GList *parent_node, GtkTreePath *tree_path, gboolean emit_signal) { FmDirTreeItem *parent_item = (FmDirTreeItem*) parent_node->data; // Check if the parent node can expand... FmFileInfo *file_info = parent_item->file_info; FmPath *path = fm_file_info_get_path (file_info); TREEVIEW_DEBUG ("TREEVIEW_DEBUG: fm_dir_tree_model_add_place_holder_child_item: file = %s\t emit_signal = %d\n", fm_file_info_get_name (file_info), emit_signal); // don't expand the trash can... // TODO_axl: add a can_expand flag into the file_info if (fm_path_is_trash (path) && fm_path_is_root (path)) return; TREEVIEW_DEBUG ("TREEVIEW_DEBUG: fm_dir_tree_model_add_place_holder_child_item: create place holder\n\n"); FmDirTreeItem *dir_tree_item = fm_dir_tree_item_new (dir_tree_model, parent_node, NULL); parent_item->children = g_list_prepend (parent_item->children, dir_tree_item); if (!emit_signal) return; GtkTreeIter it; fm_dir_tree_model_item_to_tree_iter (dir_tree_model, parent_item->children, &it); gtk_tree_path_append_index (tree_path, 0); gtk_tree_model_row_inserted (GTK_TREE_MODEL (dir_tree_model), tree_path, &it); gtk_tree_path_up (tree_path); }
gchar *get_scheme(FmFileInfo *file_info) { gchar *uri = fm_path_to_uri(fm_file_info_get_path(file_info)); gchar *scheme = g_uri_parse_scheme(uri); return scheme; }
void View::onNewTab() { Fm::FileMenu* menu = static_cast<Fm::FileMenu*>(sender()->parent()); for(GList* l = fm_file_info_list_peek_head_link(menu->files()); l; l = l->next) { FmFileInfo* file = FM_FILE_INFO(l->data); Q_EMIT openDirRequested(fm_file_info_get_path(file), OpenInNewTab); } }
void get_value(FmFileInfo *fi, GValue *value){ char* filename; int year; char year_string[10]; TagLib_File *TL_file; TagLib_Tag *TL_tag; filename = fm_path_to_str( fm_file_info_get_path(fi) ); TL_file = taglib_file_new( filename ); free( filename ); if (TL_file != NULL) { if(taglib_file_is_valid(TL_file)){ TL_tag = taglib_file_tag( TL_file ); year = taglib_tag_year( TL_tag ); if( year !=0 ){ sprintf( year_string, "%d", year ); g_value_set_string( value, year_string ); } taglib_tag_free_strings(); taglib_file_free( TL_file ); } } };
gchar *get_host_name(FmFileInfo *file_info) { /* TODO: Update to support IPv6. Different rules just for IPv6. Hence, ignoring */ gchar *host_name = NULL; gsize host_length; gchar *uri = fm_path_to_uri(fm_file_info_get_path(file_info)); gchar *user_pos = strchr(uri, ':'); if(user_pos == NULL) return ""; user_pos += 1; if(strncmp(user_pos, "//", 2) == 0) user_pos += 2; gchar *host_pos = strchr(uri, '@'); if(host_pos == NULL) host_pos = user_pos; else host_pos += 1; if(strchr(host_pos, ':') != NULL){ host_length = strcspn(host_pos, ":"); host_name = g_strndup(host_pos, host_length); } else { printf("here\n"); host_length = strcspn(host_pos, "/"); host_name = g_strndup(host_pos, host_length); } return host_name; }
void View::onOpenInTerminal() { Application* app = static_cast<Application*>(qApp); Fm::FileMenu* menu = static_cast<Fm::FileMenu*>(sender()->parent()); for(GList* l = fm_file_info_list_peek_head_link(menu->files()); l; l = l->next) { FmFileInfo* file = FM_FILE_INFO(l->data); app->openFolderInTerminal(fm_file_info_get_path(file)); } }
Q_FOREACH(DirTreeModelItem* item, rootItems_) { if(item->fileInfo_ && fm_path_equal(path, fm_file_info_get_path(item->fileInfo_))) { return item; } else { DirTreeModelItem* child = item->childFromPath(path, true); if(child) return child; } }
void View::onFileClicked(int type, FmFileInfo* fileInfo) { if(type == MiddleClick) { if(fm_file_info_is_dir(fileInfo)) { Q_EMIT openDirRequested(fm_file_info_get_path(fileInfo), OpenInNewTab); } } else { Fm::FolderView::onFileClicked(type, fileInfo); } }
static void on_files_added(FmFolder* folder, GSList* files, gpointer user_data) { GSList* l; for(l = files; l; l = l->next) { FmFileInfo* file = FM_FILE_INFO(l->data); FmPath* path = fm_file_info_get_path(file); char* path_str = fm_path_display_name(path, FALSE); g_printf("file found: %s\n", path_str); } }
static void on_open_folder_in_terminal(GtkAction* act, FmMainWin* win) { FmFileInfoList* files = fm_folder_view_dup_selected_files(win->folder_view); GList* l; for(l=fm_file_info_list_peek_head_link(files);l;l=l->next) { FmFileInfo* fi = (FmFileInfo*)l->data; if(fm_file_info_is_dir(fi) /*&& !fm_file_info_is_virtual(fi)*/) pcmanfm_open_folder_in_terminal(GTK_WINDOW(win), fm_file_info_get_path(fi)); } fm_file_info_list_unref(files); }
bool Launcher::openFolder(GAppLaunchContext* ctx, GList* folder_infos, GError** err) { GList* l = folder_infos; FmFileInfo* fi = FM_FILE_INFO(l->data); // TODO: Use services to resolve application settings // Application* app = Application::instance(); MainWindow* mainWindow = mainWindow_; if(!mainWindow) { mainWindow = new MainWindow(fm_file_info_get_path(fi)); // mainWindow->resize(app->settings().windowWidth(), app->settings().windowHeight()); } else mainWindow->chdir(fm_file_info_get_path(fi)); l = l->next; for(; l; l = l->next) { fi = FM_FILE_INFO(l->data); mainWindow->addTab(fm_file_info_get_path(fi)); } mainWindow->show(); mainWindow->raise(); return true; }
gint sort(FmFileInfo *fi1, FmFileInfo *fi2){ int result; char *filename1, *filename2; char *genre1=NULL, *genre2=NULL; TagLib_File *TL_file1, *TL_file2; filename1 = fm_path_to_str( fm_file_info_get_path(fi1) ); filename2 = fm_path_to_str( fm_file_info_get_path(fi2) ); TL_file1 = taglib_file_new( filename1 ); TL_file2 = taglib_file_new( filename2 ); free( filename1 ); free( filename2 ); if (TL_file1 != NULL) { if(taglib_file_is_valid(TL_file1)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file1 ); genre1 = taglib_tag_genre( TL_tag ); taglib_file_free( TL_file1 ); } } if (TL_file2 != NULL) { if(taglib_file_is_valid(TL_file2)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file2 ); genre2 = taglib_tag_genre( TL_tag ); taglib_file_free( TL_file2 ); } } result = strcasecmp(genre1, genre2); if (TL_file1 != NULL || TL_file2 != NULL) { taglib_tag_free_strings(); } return result; }
FmPathList* FolderView::selectedFilePaths() const { if(model_) { QModelIndexList selIndexes = mode == DetailedListMode ? selectedRows() : selectedIndexes(); if(!selIndexes.isEmpty()) { FmPathList* paths = fm_path_list_new(); QModelIndexList::const_iterator it; for(it = selIndexes.begin(); it != selIndexes.end(); ++it) { FmFileInfo* file = model_->fileInfoFromIndex(*it); fm_path_list_push_tail(paths, fm_file_info_get_path(file)); } return paths; } } return NULL; }
gchar *get_port(FmFileInfo *file_info) { /* TODO: Update for IPv6 support */ gchar *uri = fm_path_to_uri(fm_file_info_get_path(file_info)); gchar *user_pos = strchr(uri, ':') + 1; user_pos += 1; if(strncmp(user_pos, "//", 2) == 0) user_pos += 2; gchar *port_pos = strchr(user_pos, ':'); if(port_pos == NULL) return ""; gsize port_length = strcspn(port_pos, "/"); gchar *port = g_strndup(port_pos, port_length) + 1; return port; }
gchar *get_user_name(FmFileInfo *file_info) { gchar *uri = fm_path_to_uri(fm_file_info_get_path(file_info)); gsize user_length; gchar *user_pos = NULL, *user_name = NULL; user_pos = strchr(uri, ':'); if(user_pos == NULL) return ""; user_pos += 1; if(strncmp(user_pos, "//", 2) == 0) user_pos += 2; if(strchr(user_pos, '@') != NULL){ user_length = strcspn(user_pos, "@"); user_name = g_strndup(user_pos, user_length); } else { user_name = ""; } return user_name; }
void renameFile(FmFileInfo *file, QWidget *parent) { FmPath* path = fm_file_info_get_path(file); FilenameDialog dlg(parent); dlg.setWindowTitle(QObject::tr("Rename File")); dlg.setLabelText(QObject::tr("Please enter a new name:")); // FIXME: what's the best way to handle non-UTF8 filename encoding here? QString old_name = QString::fromLocal8Bit(fm_path_get_basename(path)); dlg.setTextValue(old_name); if(fm_file_info_is_dir(file)) // select filename extension for directories dlg.setSelectExtension(true); if(dlg.exec() != QDialog::Accepted) return; QString new_name = dlg.textValue(); if(new_name == old_name) return; GFile* gf = fm_path_to_gfile(path); GFile* parent_gf = g_file_get_parent(gf); GFile* dest = g_file_get_child(G_FILE(parent_gf), new_name.toLocal8Bit().data()); g_object_unref(parent_gf); GError* err = NULL; if(!g_file_move(gf, dest, GFileCopyFlags(G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NO_FALLBACK_FOR_MOVE | G_FILE_COPY_NOFOLLOW_SYMLINKS), NULL, /* make this cancellable later. */ NULL, NULL, &err)) { QMessageBox::critical(parent, QObject::tr("Error"), err->message); g_error_free(err); } g_object_unref(dest); g_object_unref(gf); }
void get_value(FmFileInfo *fi, GValue *value){ char* filename; char* genre; TagLib_File *TL_file; TagLib_Tag *TL_tag; filename = fm_path_to_str( fm_file_info_get_path(fi) ); TL_file = taglib_file_new( filename ); free( filename ); if( TL_file != NULL ) { if(taglib_file_is_valid(TL_file)){ TL_tag = taglib_file_tag( TL_file ); genre = taglib_tag_genre( TL_tag ); g_value_set_string( value, genre ); taglib_tag_free_strings(); taglib_file_free( TL_file ); } } };
// FIXME_pcm: this is too dirty. Need some refactor later. static void update_permissions (FmFilePropData *data) { FmFileInfo *file_info = (FmFileInfo*)fm_list_peek_head (data->files); GList *l; int sel; char *tmp; mode_t owner_perm = (file_info->mode & S_IRWXU); mode_t group_perm = (file_info->mode & S_IRWXG); mode_t other_perm = (file_info->mode & S_IRWXO); mode_t exec_perm = (file_info->mode & (S_IXUSR|S_IXGRP|S_IXOTH)); uid_t uid = file_info->uid; gid_t gid = file_info->gid; struct group *grp = NULL; struct passwd *pw = NULL; data->all_native = fm_path_is_native (fm_file_info_get_path (file_info)); data->has_dir = S_ISDIR (file_info->mode) != FALSE; for (l=fm_list_peek_head_link (data->files)->next; l; l=l->next) { FmFileInfo *file_info = (FmFileInfo*)l->data; if ( !fm_path_is_native (fm_file_info_get_path (file_info)) ) data->all_native = FALSE; if (S_ISDIR (file_info->mode)) data->has_dir = TRUE; if ( uid != file_info->uid ) uid = -1; if ( gid != file_info->gid ) gid = -1; if ( owner_perm != -1 && owner_perm != (file_info->mode & S_IRWXU) ) owner_perm = -1; if ( group_perm != -1 && group_perm != (file_info->mode & S_IRWXG) ) group_perm = -1; if ( other_perm != -1 && other_perm != (file_info->mode & S_IRWXO) ) other_perm = -1; if ( exec_perm != (file_info->mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ) exec_perm = -1; } if ( data->all_native ) { if ( uid >= 0 ) { pw = getpwuid (uid); if (pw) gtk_entry_set_text (GTK_ENTRY (data->owner), pw->pw_name); } if ( gid >= 0 ) { grp = getgrgid (gid); if (grp) gtk_entry_set_text (GTK_ENTRY (data->group), grp->gr_name); } } if ( uid >=0 && !pw ) { tmp = g_strdup_printf ("%u", uid); gtk_entry_set_text (GTK_ENTRY (data->owner), tmp); g_free (tmp); } if ( gid >=0 && !grp ) { tmp = g_strdup_printf ("%u", gid); gtk_entry_set_text (GTK_ENTRY (data->group), tmp); g_free (tmp); } data->orig_owner = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->owner))); data->orig_group = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->group))); // on local filesystems, only root can do chown. if ( data->all_native && geteuid () != 0 ) { gtk_editable_set_editable (GTK_EDITABLE (data->owner), FALSE); gtk_editable_set_editable (GTK_EDITABLE (data->group), FALSE); } sel = NO_CHANGE; if (owner_perm != -1) { if ( (owner_perm & (S_IRUSR|S_IWUSR)) == (S_IRUSR|S_IWUSR) ) sel = READ_WRITE; else if ( (owner_perm & (S_IRUSR|S_IWUSR)) == S_IRUSR ) sel = READ_ONLY; else if ( (owner_perm & (S_IRUSR|S_IWUSR)) == S_IWUSR ) sel = WRITE_ONLY; else sel = NONE; } gtk_combo_box_set_active (GTK_COMBO_BOX (data->owner_perm), sel); data->owner_perm_sel = sel; sel = NO_CHANGE; if (group_perm != -1) { if ( (group_perm & (S_IRGRP|S_IWGRP)) == (S_IRGRP|S_IWGRP) ) sel = READ_WRITE; else if ( (group_perm & (S_IRGRP|S_IWGRP)) == S_IRGRP ) sel = READ_ONLY; else if ( (group_perm & (S_IRGRP|S_IWGRP)) == S_IWGRP ) sel = WRITE_ONLY; else sel = NONE; } gtk_combo_box_set_active (GTK_COMBO_BOX (data->group_perm), sel); data->group_perm_sel = sel; sel = NO_CHANGE; if (other_perm != -1) { if ( (other_perm & (S_IROTH|S_IWOTH)) == (S_IROTH|S_IWOTH) ) sel = READ_WRITE; else if ( (other_perm & (S_IROTH|S_IWOTH)) == S_IROTH ) sel = READ_ONLY; else if ( (other_perm & (S_IROTH|S_IWOTH)) == S_IWOTH ) sel = WRITE_ONLY; else sel = NONE; } gtk_combo_box_set_active (GTK_COMBO_BOX (data->other_perm), sel); data->other_perm_sel = sel; if (data->has_dir) gtk_widget_hide ( data->exec ); if ( exec_perm != -1 ) { gboolean xusr = (exec_perm & S_IXUSR) != 0; gboolean xgrp = (exec_perm & S_IXGRP) != 0; gboolean xoth = (exec_perm & S_IXOTH) != 0; if ( xusr == xgrp && xusr == xoth ) // executable { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->exec), xusr); data->exec_state = xusr; } else // inconsistent { gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (data->exec), TRUE); g_signal_connect (data->exec, "toggled", G_CALLBACK (on_exec_toggled), data); data->exec_state = -1; } } else // inconsistent { gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (data->exec), TRUE); g_signal_connect (data->exec, "toggled", G_CALLBACK (on_exec_toggled), data); data->exec_state = -1; } }
/** * fm_launch_files * @ctx: (allow-none): a launch context * @file_infos: (element-type FmFileInfo): files to launch * @launcher: #FmFileLauncher with callbacks * @user_data: data supplied for callbacks * * Launches files using callbacks in @launcher. * * Returns: %TRUE in case of success. * * Since: 0.1.0 */ gboolean fm_launch_files(GAppLaunchContext* ctx, GList* file_infos, FmFileLauncher* launcher, gpointer user_data) { GList* l; GHashTable* hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); GList *folders = NULL; FmFileInfo* fi; GList *targets = NULL; GError* err = NULL; GAppInfo* app; const char* type; for(l = file_infos; l; l=l->next) { GList* fis; char *filename, *scheme; const char *target = NULL; fi = (FmFileInfo*)l->data; /* special handling for shortcuts */ if (!fm_file_info_is_symlink(fi)) /* symlinks also has fi->target, but we only handle shortcuts here. */ target = fm_file_info_get_target(fi); if (launcher->open_folder && fm_file_info_is_dir(fi)) { /* special handling for shortcuts */ if(target) { fi = _fetch_file_info_for_shortcut(fm_file_info_get_target(fi), ctx, launcher, user_data); if (fi == NULL) /* error was shown by job already */ continue; targets = g_list_prepend(targets, fi); } folders = g_list_prepend(folders, fi); } else if (fm_file_info_is_desktop_entry(fi)) { _launch_desktop_entry: if (!target) filename = fm_path_to_str(fm_file_info_get_path(fi)); fm_launch_desktop_entry(ctx, target ? target : filename, NULL, launcher, user_data); if (!target) g_free(filename); continue; } else { FmPath* path = fm_file_info_get_path(fi); FmMimeType* mime_type = NULL; if(fm_path_is_native(path)) { /* special handling for shortcuts */ if (target) { if (fm_file_info_get_mime_type(fi) == _fm_mime_type_get_inode_x_shortcut()) /* if we already know MIME type then use it instead */ { scheme = g_uri_parse_scheme(target); if (scheme) { /* FIXME: this is rough! */ if (strcmp(scheme, "file") != 0 && strcmp(scheme, "trash") != 0 && strcmp(scheme, "network") != 0 && strcmp(scheme, "computer") != 0 && strcmp(scheme, "menu") != 0) { /* we don't support this URI internally, try GIO */ app = g_app_info_get_default_for_uri_scheme(scheme); if (app) { fis = g_list_prepend(NULL, (char *)target); fm_app_info_launch_uris(app, fis, ctx, &err); g_list_free(fis); g_object_unref(app); } else if (launcher->error) g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, _("No default application is set to launch URIs %s://"), scheme); if (err) { launcher->error(ctx, err, NULL, user_data); g_clear_error(&err); } g_free(scheme); continue; } g_free(scheme); } } else mime_type = fm_file_info_get_mime_type(fi); /* retrieve file info for target otherwise and handle it */ fi = _fetch_file_info_for_shortcut(target, ctx, launcher, user_data); if (fi == NULL) /* error was shown by job already */ continue; targets = g_list_prepend(targets, fi); path = fm_file_info_get_path(fi); /* special handling for desktop entries */ if (fm_file_info_is_desktop_entry(fi)) goto _launch_desktop_entry; } if(fm_file_info_is_executable_type(fi)) { /* if it's an executable file, directly execute it. */ filename = fm_path_to_str(path); /* FIXME: we need to use eaccess/euidaccess here. */ if(g_file_test(filename, G_FILE_TEST_IS_EXECUTABLE)) { if(launcher->exec_file) { FmFileLauncherExecAction act = launcher->exec_file(fi, user_data); GAppInfoCreateFlags flags = 0; switch(act) { case FM_FILE_LAUNCHER_EXEC_IN_TERMINAL: flags |= G_APP_INFO_CREATE_NEEDS_TERMINAL; /* NOTE: no break here */ case FM_FILE_LAUNCHER_EXEC: { /* filename may contain spaces. Fix #3143296 */ char* quoted = g_shell_quote(filename); app = fm_app_info_create_from_commandline(quoted, NULL, flags, NULL); g_free(quoted); if(app) { char* run_path = g_path_get_dirname(filename); char* cwd = NULL; /* bug #3589641: scripts are ran from $HOME. since GIO launcher is kinda ugly - it has no means to set running directory so we do workaround - change directory to it */ if(run_path && strcmp(run_path, ".")) { cwd = g_get_current_dir(); if(chdir(run_path) != 0) { g_free(cwd); cwd = NULL; if (launcher->error) { g_set_error(&err, G_IO_ERROR, g_io_error_from_errno(errno), _("Cannot set working directory to '%s': %s"), run_path, g_strerror(errno)); launcher->error(ctx, err, NULL, user_data); g_clear_error(&err); } } } g_free(run_path); if(!fm_app_info_launch(app, NULL, ctx, &err)) { if(launcher->error) launcher->error(ctx, err, NULL, user_data); g_error_free(err); err = NULL; } if(cwd) /* return back */ { if(chdir(cwd) != 0) g_warning("fm_launch_files(): chdir() failed"); g_free(cwd); } g_object_unref(app); continue; } break; } case FM_FILE_LAUNCHER_EXEC_OPEN: break; case FM_FILE_LAUNCHER_EXEC_CANCEL: continue; } } } g_free(filename); } } if (mime_type == NULL) mime_type = fm_file_info_get_mime_type(fi); if(mime_type && (type = fm_mime_type_get_type(mime_type))) { fis = g_hash_table_lookup(hash, type); fis = g_list_prepend(fis, fi); g_hash_table_insert(hash, (gpointer)type, fis); } else if (launcher->error) { g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, _("Could not determine content type of file '%s' to launch it"), fm_file_info_get_disp_name(fi)); launcher->error(ctx, err, NULL, user_data); g_clear_error(&err); } } } if(g_hash_table_size(hash) > 0) { GHashTableIter it; GList* fis; g_hash_table_iter_init(&it, hash); while(g_hash_table_iter_next(&it, (void**)&type, (void**)&fis)) { GAppInfo* app = g_app_info_get_default_for_type(type, FALSE); if(!app) { if(launcher->get_app) { FmMimeType* mime_type = fm_file_info_get_mime_type((FmFileInfo*)fis->data); app = launcher->get_app(fis, mime_type, user_data, NULL); } } if(app) { for(l=fis; l; l=l->next) { char* uri; fi = (FmFileInfo*)l->data; /* special handling for shortcuts */ if (fm_file_info_is_shortcut(fi)) uri = g_strdup(fm_file_info_get_target(fi)); else uri = fm_path_to_uri(fm_file_info_get_path(fi)); l->data = uri; } fis = g_list_reverse(fis); fm_app_info_launch_uris(app, fis, ctx, &err); /* free URI strings */ g_list_foreach(fis, (GFunc)g_free, NULL); g_object_unref(app); } else if (launcher->error) g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, _("No default application is set for MIME type %s"), type); if (err) { launcher->error(ctx, err, NULL, user_data); g_clear_error(&err); } g_list_free(fis); } } g_hash_table_destroy(hash); if(folders) { folders = g_list_reverse(folders); if(launcher->open_folder) { launcher->open_folder(ctx, folders, user_data, &err); if(err) { if(launcher->error) launcher->error(ctx, err, NULL, user_data); g_error_free(err); err = NULL; } } g_list_free(folders); } g_list_free_full(targets, (GDestroyNotify)fm_file_info_unref); return TRUE; }
static gint on_ask_rename(FmFileOpsJob* job, FmFileInfo* src, FmFileInfo* dest, char** new_name, FmProgressDisplay* data) { int res; GtkBuilder* builder; GtkDialog *dlg; GtkImage *src_icon, *dest_icon; GtkLabel *src_fi, *dest_fi; GtkEntry *filename; GtkToggleButton *apply_all; char* tmp; const char* disp_size; FmPath* path; FmIcon* icon; /* return default operation if the user has set it */ if(data->default_opt) return data->default_opt; builder = gtk_builder_new(); path = fm_file_info_get_path(dest); icon = fm_file_info_get_icon(src); if(data->timer) g_timer_stop(data->timer); gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE); ensure_dlg(data); gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/ask-rename.ui", NULL); dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg")); src_icon = GTK_IMAGE(gtk_builder_get_object(builder, "src_icon")); src_fi = GTK_LABEL(gtk_builder_get_object(builder, "src_fi")); dest_icon = GTK_IMAGE(gtk_builder_get_object(builder, "dest_icon")); dest_fi = GTK_LABEL(gtk_builder_get_object(builder, "dest_fi")); filename = GTK_ENTRY(gtk_builder_get_object(builder, "filename")); apply_all = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "apply_all")); gtk_window_set_transient_for(GTK_WINDOW(dlg), GTK_WINDOW(data->dlg)); gtk_image_set_from_gicon(src_icon, icon->gicon, GTK_ICON_SIZE_DIALOG); disp_size = fm_file_info_get_disp_size(src); if(disp_size) { tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"), fm_file_info_get_desc(src), disp_size, fm_file_info_get_disp_mtime(src)); } else { tmp = g_strdup_printf(_("Type: %s\nModified: %s"), fm_file_info_get_desc(src), fm_file_info_get_disp_mtime(src)); } gtk_label_set_text(src_fi, tmp); g_free(tmp); gtk_image_set_from_gicon(dest_icon, icon->gicon, GTK_ICON_SIZE_DIALOG); disp_size = fm_file_info_get_disp_size(dest); if(disp_size) { tmp = g_strdup_printf(_("Type: %s\nSize: %s\nModified: %s"), fm_file_info_get_desc(dest), fm_file_info_get_disp_size(dest), fm_file_info_get_disp_mtime(dest)); } else { tmp = g_strdup_printf(_("Type: %s\nModified: %s"), fm_file_info_get_desc(dest), fm_file_info_get_disp_mtime(dest)); } gtk_label_set_text(dest_fi, tmp); g_free(tmp); tmp = g_filename_display_name(fm_path_get_basename(path)); gtk_entry_set_text(filename, tmp); g_free(tmp); tmp = (char*)fm_file_info_get_disp_name(dest); /* FIXME: cast const to char */ g_object_set_data(G_OBJECT(filename), "old_name", tmp); g_signal_connect(filename, "changed", G_CALLBACK(on_filename_changed), gtk_builder_get_object(builder, "rename")); g_object_unref(builder); res = gtk_dialog_run(dlg); switch(res) { case RESPONSE_RENAME: *new_name = g_strdup(gtk_entry_get_text(filename)); res = FM_FILE_OP_RENAME; break; case RESPONSE_OVERWRITE: res = FM_FILE_OP_OVERWRITE; break; case RESPONSE_SKIP: res = FM_FILE_OP_SKIP; break; default: res = FM_FILE_OP_CANCEL; } if(gtk_toggle_button_get_active(apply_all)) { if(res == RESPONSE_OVERWRITE || res == FM_FILE_OP_SKIP) data->default_opt = res; } gtk_widget_destroy(GTK_WIDGET(dlg)); if(data->timer) g_timer_continue(data->timer); return res; }
RenameDialog::RenameDialog(FmFileInfo* src, FmFileInfo* dest, QWidget* parent, Qt::WindowFlags f): QDialog(parent, f), action_(ActionIgnore), applyToAll_(false) { ui = new Ui::RenameDialog(); ui->setupUi(this); FmPath* path = fm_file_info_get_path(dest); FmIcon* srcIcon = fm_file_info_get_icon(src); FmIcon* destIcon = fm_file_info_get_icon(dest); // show info for the source file QIcon icon = IconTheme::icon(srcIcon); QSize iconSize(fm_config->big_icon_size, fm_config->big_icon_size); QPixmap pixmap = icon.pixmap(iconSize); ui->srcIcon->setPixmap(pixmap); QString infoStr; const char* disp_size = fm_file_info_get_disp_size(src); if(disp_size) { infoStr = QString(tr("Type: %1\nSize: %2\nModified: %3")) .arg(QString::fromUtf8(fm_file_info_get_desc(src))) .arg(QString::fromUtf8(disp_size)) .arg(QString::fromUtf8(fm_file_info_get_disp_mtime(src))); } else { infoStr = QString(tr("Type: %1\nModified: %2")) .arg(QString::fromUtf8(fm_file_info_get_desc(src))) .arg(QString::fromUtf8(fm_file_info_get_disp_mtime(src))); } ui->srcInfo->setText(infoStr); // show info for the dest file icon = IconTheme::icon(destIcon); pixmap = icon.pixmap(iconSize); ui->destIcon->setPixmap(pixmap); disp_size = fm_file_info_get_disp_size(dest); if(disp_size) { infoStr = QString(tr("Type: %1\nSize: %2\nModified: %3")) .arg(QString::fromUtf8(fm_file_info_get_desc(dest))) .arg(QString::fromUtf8(disp_size)) .arg(QString::fromUtf8(fm_file_info_get_disp_mtime(dest))); } else { infoStr = QString(tr("Type: %1\nModified: %3")) .arg(QString::fromUtf8(fm_file_info_get_desc(src))) .arg(QString::fromUtf8(fm_file_info_get_disp_mtime(src))); } ui->destInfo->setText(infoStr); char* basename = fm_path_display_basename(path); ui->fileName->setText(QString::fromUtf8(basename)); oldName_ = basename; g_free(basename); connect(ui->fileName, &QLineEdit::textChanged, this, &RenameDialog::onFileNameChanged); // add "Rename" button QAbstractButton* button = ui->buttonBox->button(QDialogButtonBox::Ok); button->setText(tr("&Overwrite")); // FIXME: there seems to be no way to place the Rename button next to the overwrite one. renameButton_ = ui->buttonBox->addButton(tr("&Rename"), QDialogButtonBox::ActionRole); connect(renameButton_, &QPushButton::clicked, this, &RenameDialog::onRenameClicked); renameButton_->setEnabled(false); // disabled by default button = ui->buttonBox->button(QDialogButtonBox::Ignore); connect(button, &QPushButton::clicked, this, &RenameDialog::onIgnoreClicked); }
static gpointer _dentry_ui_init(GtkBuilder *ui, gpointer uidata, FmFileInfoList *files) { GObject *widget; GtkWidget *new_widget; FmFilePropertiesDEntryData *data; GtkTable *table; GtkLabel *label; GError *err = NULL; FmFileInfo *fi; GFile *gf; gchar *txt; gsize length; const gchar * const *langs; gboolean tmp_bool; /* disable permissions tab and open_with in any case */ #define HIDE_WIDGET(x) widget = gtk_builder_get_object(ui, x); \ gtk_widget_hide(GTK_WIDGET(widget)) /* HIDE_WIDGET("permissions_tab"); TODO: made visibility of permissions_tab configurable */ table = GTK_TABLE(gtk_builder_get_object(ui, "general_table")); HIDE_WIDGET("open_with"); HIDE_WIDGET("open_with_label"); gtk_table_set_row_spacing(table, 5, 0); /* we will do the thing only for single file! */ if (fm_file_info_list_get_length(files) != 1) return NULL; fi = fm_file_info_list_peek_head(files); gf = fm_path_to_gfile(fm_file_info_get_path(fi)); if (!g_file_load_contents(gf, NULL, &txt, &length, NULL, NULL)) { g_warning("file properties dialog: cannot access desktop entry file"); g_object_unref(gf); return NULL; } data = g_slice_new(FmFilePropertiesDEntryData); data->changed = FALSE; data->file = gf; data->kf = g_key_file_new(); g_key_file_load_from_data(data->kf, txt, length, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); g_free(txt); /* FIXME: handle errors, also do g_key_file_has_group() */ /* get locale name */ data->lang = NULL; langs = g_get_language_names(); if (strcmp(langs[0], "C") != 0) { /* remove encoding from locale name */ char *sep = strchr(langs[0], '.'); if (sep) data->lang = g_strndup(langs[0], sep - langs[0]); else data->lang = g_strdup(langs[0]); } /* enable events for icon */ widget = gtk_builder_get_object(ui, "icon_eventbox"); data->icon = gtk_builder_get_object(ui, "icon"); gtk_widget_set_can_focus(GTK_WIDGET(widget), TRUE); /* disable Name event handler in the widget */ widget = gtk_builder_get_object(ui, "name"); g_signal_handlers_block_matched(widget, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, uidata); g_signal_connect(widget, "changed", G_CALLBACK(_dentry_name_changed), data); data->name = GTK_ENTRY(widget); data->saved_name = g_strdup(gtk_entry_get_text(data->name)); /* FIXME: two lines below is temporary workaround on FIXME in widget */ gtk_widget_set_can_focus(GTK_WIDGET(widget), TRUE); gtk_editable_set_editable(GTK_EDITABLE(widget), TRUE); /* Name is set from "Name" by libfm already so don't touch it */ /* support 'hidden' option */ data->hidden = NULL; widget = gtk_builder_get_object(ui, "hidden"); if (widget && GTK_IS_TOGGLE_BUTTON(widget) && fm_file_info_is_native(fi)) { data->hidden = (GtkToggleButton*)widget; data->was_hidden = fm_file_info_is_hidden(fi); g_signal_connect(widget, "toggled", G_CALLBACK(_dentry_hidden_toggled), data); gtk_widget_set_can_focus(GTK_WIDGET(data->hidden), TRUE); /* set sensitive since it can be toggled for desktop entry */ gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE); gtk_widget_show(GTK_WIDGET(data->hidden)); } #undef HIDE_WIDGET /* FIXME: migrate to GtkGrid */ table = GTK_TABLE(gtk_table_new(8, 2, FALSE)); gtk_table_set_row_spacings(table, 4); gtk_table_set_col_spacings(table, 12); gtk_container_set_border_width(GTK_CONTAINER(table), 4); /* row 0: "Exec" GtkHBox: GtkEntry+GtkButton */ new_widget = gtk_label_new(NULL); label = GTK_LABEL(new_widget); gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0); gtk_label_set_markup_with_mnemonic(label, _("<b>Co_mmand:</b>")); gtk_table_attach(table, new_widget, 0, 1, 0, 1, GTK_FILL, 0, 0, 0); #if GTK_CHECK_VERSION(3, 2, 0) /* FIXME: migrate to GtkGrid */ widget = G_OBJECT(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6)); #else widget = G_OBJECT(gtk_hbox_new(FALSE, 6)); #endif new_widget = gtk_button_new_with_mnemonic(_("_Browse...")); gtk_box_pack_end(GTK_BOX(widget), new_widget, FALSE, FALSE, 0); g_signal_connect(new_widget, "clicked", G_CALLBACK(_dentry_browse_exec_event), data); new_widget = gtk_entry_new(); data->exec = GTK_ENTRY(new_widget); txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Exec", NULL, NULL); if (txt) { gtk_entry_set_text(data->exec, txt); g_free(txt); } gtk_widget_set_tooltip_text(new_widget, _("Command to execute when the application icon is activated")); gtk_box_pack_start(GTK_BOX(widget), new_widget, TRUE, TRUE, 0); g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_exec_changed), data); gtk_table_attach(table, GTK_WIDGET(widget), 1, 2, 0, 1, GTK_FILL|GTK_EXPAND, 0, 0, 0); gtk_label_set_mnemonic_widget(label, new_widget); /* row 1: "Terminal" GtkCheckButton */ new_widget = gtk_check_button_new_with_mnemonic(_("_Execute in terminal emulator")); data->terminal = GTK_TOGGLE_BUTTON(new_widget); tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "Terminal", &err); if (err) /* no such key present */ { tmp_bool = FALSE; g_clear_error(&err); } gtk_toggle_button_set_active(data->terminal, tmp_bool); g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_terminal_toggled), data); gtk_table_attach(table, new_widget, 0, 2, 1, 2, GTK_FILL, 0, 18, 0); /* row 2: "X-KeepTerminal" GtkCheckButton */ new_widget = gtk_check_button_new_with_mnemonic(_("_Keep terminal window open after command execution")); data->keep_open = GTK_TOGGLE_BUTTON(new_widget); gtk_widget_set_sensitive(new_widget, tmp_bool); /* disable if not in terminal */ tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "X-KeepTerminal", &err); if (err) /* no such key present */ { tmp_bool = FALSE; g_clear_error(&err); } gtk_toggle_button_set_active(data->keep_open, tmp_bool); g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_keepterm_toggled), data); gtk_table_attach(table, new_widget, 0, 2, 2, 3, GTK_FILL, 0, 27, 0); /* row 4: "GenericName" GtkEntry */ new_widget = gtk_label_new(NULL); label = GTK_LABEL(new_widget); gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0); gtk_label_set_markup_with_mnemonic(label, _("<b>D_escription:</b>")); gtk_table_attach(table, new_widget, 0, 1, 4, 5, GTK_FILL, 0, 0, 0); new_widget = gtk_entry_new(); data->generic_name = GTK_ENTRY(new_widget); txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "GenericName", NULL, NULL); if (txt) { gtk_entry_set_text(data->generic_name, txt); g_free(txt); } gtk_widget_set_tooltip_text(new_widget, _("Generic name of the application")); g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_genname_changed), data); gtk_table_attach(table, new_widget, 1, 2, 4, 5, GTK_FILL|GTK_EXPAND, 0, 0, 0); gtk_label_set_mnemonic_widget(label, new_widget); /* row 3: "Path" GtkEntry */ new_widget = gtk_label_new(NULL); label = GTK_LABEL(new_widget); gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0); gtk_label_set_markup_with_mnemonic(label, _("<b>_Working directory:</b>")); gtk_table_attach(table, new_widget, 0, 1, 3, 4, GTK_FILL, 0, 0, 0); new_widget = gtk_entry_new(); data->path = GTK_ENTRY(new_widget); txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Path", NULL, NULL); if (txt) { gtk_entry_set_text(data->path, txt); g_free(txt); } gtk_widget_set_tooltip_text(new_widget, _("The working directory to run the program in")); g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_path_changed), data); gtk_table_attach(table, new_widget, 1, 2, 3, 4, GTK_FILL|GTK_EXPAND, 0, 0, 0); gtk_label_set_mnemonic_widget(label, new_widget); /* row 5: "Comment" GtkEntry */ new_widget = gtk_label_new(NULL); label = GTK_LABEL(new_widget); gtk_misc_set_alignment(GTK_MISC(new_widget), 0.0, 0.0); gtk_label_set_markup_with_mnemonic(label, _("<b>_Tooltip:</b>")); gtk_table_attach(table, new_widget, 0, 1, 5, 6, GTK_FILL, 0, 0, 0); new_widget = gtk_entry_new(); data->comment = GTK_ENTRY(new_widget); txt = g_key_file_get_locale_string(data->kf, GRP_NAME, "Comment", NULL, NULL); if (txt) { gtk_entry_set_text(data->comment, txt); g_free(txt); } gtk_widget_set_tooltip_text(new_widget, _("Tooltip to show on application")); g_signal_connect(new_widget, "changed", G_CALLBACK(_dentry_tooltip_changed), data); gtk_table_attach(table, new_widget, 1, 2, 5, 6, GTK_FILL|GTK_EXPAND, 0, 0, 0); gtk_label_set_mnemonic_widget(label, new_widget); /* TODO: handle "TryExec" field ? */ /* row 7: "StartupNotify" GtkCheckButton */ new_widget = gtk_check_button_new_with_mnemonic(_("_Use startup notification")); data->notification = GTK_TOGGLE_BUTTON(new_widget); tmp_bool = g_key_file_get_boolean(data->kf, GRP_NAME, "StartupNotify", &err); if (err) /* no such key present */ { tmp_bool = FALSE; g_clear_error(&err); } gtk_toggle_button_set_active(data->notification, tmp_bool); g_signal_connect(new_widget, "toggled", G_CALLBACK(_dentry_notification_toggled), data); gtk_table_attach(table, new_widget, 0, 2, 7, 8, GTK_FILL, 0, 0, 0); /* put the table into third tab and enable it */ widget = gtk_builder_get_object(ui, "extra_tab_label"); gtk_label_set_markup_with_mnemonic(GTK_LABEL(widget), _("_Desktop Entry")); widget = gtk_builder_get_object(ui, "extra_tab"); gtk_container_add(GTK_CONTAINER(widget), GTK_WIDGET(table)); gtk_widget_show_all(GTK_WIDGET(widget)); return data; }
void FilePropsDialog::initGeneralPage() { // update UI if(singleType) { // all files are of the same mime-type FmIcon* icon = NULL; // FIXME: handle custom icons for some files // FIXME: display special property pages for special files or // some specified mime-types. if(singleFile) { // only one file is selected. icon = fm_file_info_get_icon(fileInfo); } if(mimeType) { if(!icon) // get an icon from mime type if needed icon = fm_mime_type_get_icon(mimeType); ui->fileType->setText(QString::fromUtf8(fm_mime_type_get_desc(mimeType))); ui->mimeType->setText(QString::fromUtf8(fm_mime_type_get_type(mimeType))); } if(icon) { ui->iconButton->setIcon(IconTheme::icon(icon)); } if(singleFile && fm_file_info_is_symlink(fileInfo)) { ui->target->setText(QString::fromUtf8(fm_file_info_get_target(fileInfo))); } else { ui->target->hide(); ui->targetLabel->hide(); } } // end if(singleType) else { // not singleType, multiple files are selected at the same time ui->fileType->setText(tr("Files of different types")); ui->target->hide(); ui->targetLabel->hide(); } // FIXME: check if all files has the same parent dir, mtime, or atime if(singleFile) { // only one file is selected FmPath* parent_path = fm_path_get_parent(fm_file_info_get_path(fileInfo)); char* parent_str = parent_path ? fm_path_display_name(parent_path, true) : NULL; ui->fileName->setText(QString::fromUtf8(fm_file_info_get_disp_name(fileInfo))); if(parent_str) { ui->location->setText(QString::fromUtf8(parent_str)); g_free(parent_str); } else ui->location->clear(); ui->lastModified->setText(QString::fromUtf8(fm_file_info_get_disp_mtime(fileInfo))); // FIXME: need to encapsulate this in an libfm API. time_t atime; struct tm tm; atime = fm_file_info_get_atime(fileInfo); localtime_r(&atime, &tm); char buf[128]; strftime(buf, sizeof(buf), "%x %R", &tm); ui->lastAccessed->setText(QString::fromUtf8(buf)); } else { ui->fileName->setText(tr("Multiple Files")); ui->fileName->setEnabled(false); } initApplications(); // init applications combo box // calculate total file sizes fileSizeTimer = new QTimer(this); connect(fileSizeTimer, &QTimer::timeout, this, &FilePropsDialog::onFileSizeTimerTimeout); fileSizeTimer->start(600); g_signal_connect(deepCountJob, "finished", G_CALLBACK(onDeepCountJobFinished), this); gboolean ret = fm_job_run_async(FM_JOB(deepCountJob)); }
static gboolean fm_file_info_job_run(FmJob* fmjob) { GList* l; FmFileInfoJob* job = (FmFileInfoJob*)fmjob; GError* err = NULL; if(job->file_infos == NULL) return FALSE; for(l = fm_file_info_list_peek_head_link(job->file_infos); !fm_job_is_cancelled(fmjob) && l;) { FmFileInfo* fi = (FmFileInfo*)l->data; GList* next = l->next; FmPath* path = fm_file_info_get_path(fi); if(job->current) fm_path_unref(job->current); job->current = fm_path_ref(path); if(fm_path_is_native(path)) { char* path_str = fm_path_to_str(path); if(!_fm_file_info_job_get_info_for_native_file(fmjob, fi, path_str, &err)) { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_free(path_str); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); g_free(path_str); /* recursively set display names for path parents */ _check_native_display_names(fm_path_get_parent(path)); } else { GFile* gf; gf = fm_path_to_gfile(path); if(!_fm_file_info_job_get_info_for_gfile(fmjob, fi, gf, &err)) { if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED) { GFileInfo *inf; /* location by link isn't mounted; unfortunately we cannot launch a target if we don't know what kind of target we have; lets make a simplest directory-kind GFIleInfo */ /* FIXME: this may be dirty a bit */ g_error_free(err); err = NULL; inf = g_file_info_new(); g_file_info_set_file_type(inf, G_FILE_TYPE_DIRECTORY); g_file_info_set_name(inf, fm_path_get_basename(path)); g_file_info_set_display_name(inf, fm_path_get_basename(path)); fm_file_info_set_from_g_file_data(fi, gf, inf); g_object_unref(inf); } else { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_object_unref(gf); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ goto _next; } } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); /* recursively set display names for path parents */ _check_gfile_display_names(fm_path_get_parent(path), gf); _next: g_object_unref(gf); } l = next; } return TRUE; }
/* NOTE: Sticking to natural behavior of returning a list with the unchanged input_string, incase nothing can be substituted, however, this is expensive. A better way would be to return NULL incase of no changes, and let the caller handle the NULL case, which implies that there is no change in the input_string */ GPtrArray* substitute_parameters(gchar *input_string, FmFileInfoList *file_info_list) { //printf("Input string is %s\n", input_string); GPtrArray *out_string_array = g_ptr_array_new(); if(strchr(input_string, '%') == NULL){ //printf("Found nothing to expand. Returning input_string.\n"); g_ptr_array_add(out_string_array, g_string_new(input_string)); return out_string_array; } gsize i, j; gsize len_file_list = fm_list_get_length(file_info_list); GString *out_string = g_string_new(NULL); gsize first_pos = strcspn(input_string, "%"); gchar *pos = input_string + first_pos; g_string_append_len(out_string, input_string, first_pos); GString *g_string_i = NULL; gchar *base_name = NULL, *base_dir = NULL, *file_name = NULL, *host_name = NULL, *user_name = NULL, *port = NULL, *scheme = NULL, *uri = NULL, *file_name_wo_ext = NULL, *ext_pos = NULL; gboolean array_is_init = FALSE; FmFileInfo *file_info_i = NULL, *file_info_j = NULL; char temp[256]; gboolean curr_dir_flag; while((pos = strchr(pos, '%')) != NULL){ switch(pos[1]){ case 'b': /* Works */ if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ g_string_i = g_string_new(out_string->str); file_info_i = fm_list_peek_nth(file_info_list, i); base_name = (gchar *)fm_file_info_get_disp_name(file_info_i); g_string_append(g_string_i, base_name); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_string_free(g_string_i, TRUE); } break; } file_info_i = fm_list_peek_head(file_info_list); base_name = (gchar *)fm_file_info_get_disp_name(file_info_i); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, base_name); g_string_append_c(g_string_i, ' '); } break; case 'B': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); base_name = (gchar *)fm_file_info_get_disp_name(file_info_j); g_string_append(g_string_i, base_name); g_string_append_c(g_string_i, ' '); } } break; case 'c': /* Works */ memset(temp, 256, 0); if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); sprintf(temp, "%u", len_file_list); g_string_append(g_string_i, temp); g_string_append_c(g_string_i, ' '); } break; case 'd': /* Works */ curr_dir_flag = FALSE; if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ g_string_i = g_string_new(out_string->str); file_info_i = fm_list_peek_nth(file_info_list, i); if(fm_file_info_is_dir(file_info_i) == TRUE){ base_dir = fm_path_to_str(fm_file_info_get_path(file_info_i)); } else { if(curr_dir_flag == FALSE){ base_dir = g_get_current_dir(); curr_dir_flag = TRUE; } else { continue; } } g_string_append(g_string_i, base_dir); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_free(base_dir); g_string_free(g_string_i, TRUE); } break; } file_info_i = fm_list_peek_head(file_info_list); if(fm_file_info_is_dir(file_info_i) == TRUE){ base_dir = fm_path_to_str(fm_file_info_get_path(file_info_i)); } else { if(curr_dir_flag == FALSE){ base_dir = g_get_current_dir(); curr_dir_flag = TRUE; } else { continue; } } for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, base_dir); g_string_append_c(g_string_i, ' '); } g_free(base_dir); break; case 'D': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ curr_dir_flag = FALSE; g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); if(fm_file_info_is_dir(file_info_j) == TRUE){ base_dir = fm_path_to_str(fm_file_info_get_path(file_info_j)); } else { if(curr_dir_flag == FALSE){ base_dir = g_get_current_dir(); curr_dir_flag = TRUE; } else { continue; } } g_string_append(g_string_i, base_dir); g_string_append_c(g_string_i, ' '); g_free(base_dir); } } break; case 'f': /* Works */ if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ g_string_i = g_string_new(out_string->str); file_info_i = fm_list_peek_nth(file_info_list, i); file_name = (gchar *)fm_path_to_str(fm_file_info_get_path(file_info_i)); g_string_append(g_string_i, file_name); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_free(file_name); g_string_free(g_string_i, TRUE); } break; } file_info_i = fm_list_peek_head(file_info_list); file_name = (gchar *)fm_path_to_str(fm_file_info_get_path(file_info_i)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, file_name); g_string_append_c(g_string_i, ' '); } g_free(file_name); break; case 'F': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); file_name = (gchar *)fm_path_to_str(fm_file_info_get_path(file_info_j)); g_string_append(g_string_i, file_name); g_string_append_c(g_string_i, ' '); g_free(file_name); } } break; case 'h': if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); file_info_i = fm_list_peek_nth(file_info_list, i); host_name = get_host_name(file_info_i); g_string_append(g_string_i, host_name); g_string_append_c(g_string_i, ' '); } break; case 'n': if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); file_info_i = fm_list_peek_nth(file_info_list, i); user_name = get_user_name(file_info_i); g_string_append(g_string_i, user_name); g_string_append_c(g_string_i, ' '); } break; case 'p': if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); file_info_i = fm_list_peek_nth(file_info_list, i); port = get_port(file_info_i); g_string_append(g_string_i, port); g_string_append_c(g_string_i, ' '); } break; case 's': if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); file_info_i = fm_list_peek_nth(file_info_list, i); scheme = get_scheme(file_info_i); g_string_append(g_string_i, scheme); g_string_append_c(g_string_i, ' '); } break; case 'u': /* Works */ if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ g_string_i = g_string_new(out_string->str); file_info_i = fm_list_peek_nth(file_info_list, i); uri = fm_path_to_uri(fm_file_info_get_path(file_info_i)); g_string_append(g_string_i, uri); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_string_free(g_string_i, TRUE); } break; } file_info_i = fm_list_peek_head(file_info_list); uri = fm_path_to_uri(fm_file_info_get_path(file_info_i)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, uri); g_string_append_c(g_string_i, ' '); } break; case 'U': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); uri = fm_path_to_uri(fm_file_info_get_path(file_info_j)); g_string_append(g_string_i, uri); g_string_append_c(g_string_i, ' '); } } break; case 'w': /* Works */ if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ g_string_i = g_string_new(out_string->str); file_info_i = fm_list_peek_nth(file_info_list, i); file_name = (gchar *)fm_file_info_get_disp_name(file_info_i); //printf("%s\n", file_name); ext_pos = g_strrstr(fm_file_info_get_disp_name(fm_list_peek_nth(file_info_list, i)), "."); if(ext_pos != NULL) file_name_wo_ext = g_strndup(file_name, strlen(file_name) - strlen(ext_pos)); else file_name_wo_ext = g_strdup(file_name); g_string_append(g_string_i, file_name_wo_ext); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_free(file_name_wo_ext); g_string_free(g_string_i, TRUE); } break; } file_info_i = fm_list_peek_head(file_info_list); file_name = (gchar *)fm_file_info_get_disp_name(file_info_i); ext_pos = g_strrstr(file_name, "."); if(ext_pos != NULL) file_name_wo_ext = g_strndup(file_name, strlen(file_name) - strlen(ext_pos)); else file_name_wo_ext = g_strdup(file_name); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, file_name_wo_ext); g_string_append_c(g_string_i, ' '); } g_free(file_name_wo_ext); break; case 'W': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); file_name = (gchar *)fm_file_info_get_disp_name(file_info_j); ext_pos = g_strrstr(file_name, "."); if(ext_pos != NULL) file_name_wo_ext = g_strndup(file_name, strlen(file_name) - strlen(ext_pos)); else file_name_wo_ext = g_strdup(file_name); g_string_append(g_string_i, file_name_wo_ext); g_string_append_c(g_string_i, ' '); g_free(file_name_wo_ext); } } break; case 'x': /* Works */ if(array_is_init == FALSE){ for(i=0; i<len_file_list; ++i){ file_info_i = fm_list_peek_nth(file_info_list, i); file_name = (gchar *)fm_file_info_get_disp_name(file_info_i); ext_pos = g_strrstr(file_name, "."); if(ext_pos != NULL){ g_string_i = g_string_new(out_string->str); g_string_append(g_string_i, ext_pos); g_string_append_c(g_string_i, ' '); g_ptr_array_add(out_string_array, g_string_new(g_string_i->str)); g_free(file_name_wo_ext); g_string_free(g_string_i, TRUE); } } break; } file_info_i = fm_list_peek_head(file_info_list); file_name = (gchar *)fm_file_info_get_disp_name(file_info_i); ext_pos = g_strrstr(file_name, "."); if(ext_pos == NULL) break; for(i=0; i<out_string_array->len;++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, ext_pos); g_string_append_c(g_string_i, ' '); } break; case 'X': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); for(j=0; j<len_file_list; ++j){ file_info_j= fm_list_peek_nth(file_info_list, j); file_name = (gchar *)fm_file_info_get_disp_name(file_info_j); ext_pos = g_strrstr(file_name, "."); if(ext_pos != NULL){ g_string_append(g_string_i, ext_pos); g_string_append_c(g_string_i, ' '); } } } break; case '%': /* Works */ if(array_is_init == FALSE) g_ptr_array_add(out_string_array, g_string_new(out_string->str)); for(i=0; i<out_string_array->len; ++i){ g_string_i = (GString *)g_ptr_array_index(out_string_array, i); g_string_append(g_string_i, "% "); } break; default: return NULL; } pos += 2; (array_is_init == FALSE)?array_is_init = TRUE:0; } return out_string_array; }
static gint _compare_finfo(gconstpointer p1, gconstpointer pth) { return _compare_path(fm_file_info_get_path(p1), pth); }
static void update_ui (FmFilePropData *data) { GtkImage *img = (GtkImage*) data->icon; if ( data->single_type ) // all files are of the same mime-type { GIcon *icon = NULL; // FIXME_pcm: handle custom icons for some files /* FIXME_pcm: display special property pages for special files or * some specified mime-types. */ if ( data->single_file ) // only one file is selected. { FmFileInfo *file_info = (FmFileInfo*)fm_list_peek_head (data->files); icon = fm_file_info_get_gicon (file_info); } if (data->mime_type) { if (!icon) { FmIcon *ficon = fm_mime_type_get_icon (data->mime_type); if (ficon) icon = ficon->gicon; } gtk_label_set_text (GTK_LABEL (data->type), fm_mime_type_get_desc (data->mime_type)); } if (icon) gtk_image_set_from_gicon (img, icon, GTK_ICON_SIZE_DIALOG); if ( data->single_file && fm_file_info_is_symlink (data->file_info) ) { gtk_widget_show (data->target_label); gtk_widget_show (data->target); gtk_label_set_text (GTK_LABEL (data->target), fm_file_info_get_target (data->file_info)); // gtk_label_set_text (data->type, fm_mime_type_get_desc (data->mime_type)); } else { gtk_widget_destroy (data->target_label); gtk_widget_destroy (data->target); } } else { gtk_image_set_from_stock (img, GTK_STOCK_DND_MULTIPLE, GTK_ICON_SIZE_DIALOG); gtk_widget_set_sensitive (data->name, FALSE); gtk_label_set_text (GTK_LABEL (data->type), _("Files of different types")); gtk_widget_destroy (data->target_label); gtk_widget_destroy (data->target); gtk_widget_destroy (data->open_with_label); gtk_widget_destroy (data->open_with); data->open_with = data->open_with_label = NULL; } // FIXME_pcm: check if all files has the same parent dir, mtime, or atime if ( data->single_file ) { char buf[128]; FmPath *parent = fm_path_get_parent (fm_file_info_get_path (data->file_info)); char *parent_str = parent ? fm_path_display_name (parent, TRUE) : NULL; gtk_entry_set_text (GTK_ENTRY (data->name), fm_file_info_get_disp_name (data->file_info)); if (parent_str) { gtk_label_set_text (GTK_LABEL (data->dir), parent_str); g_free (parent_str); } else gtk_label_set_text (GTK_LABEL (data->dir), ""); gtk_label_set_text (GTK_LABEL (data->mtime), fm_file_info_get_disp_mtime (data->file_info)); // FIXME_pcm: need to encapsulate this in an libfm API. strftime ( buf, sizeof ( buf ), "%x %R", localtime ( &data->file_info->atime ) ); gtk_label_set_text (GTK_LABEL (data->atime), buf); } else { gtk_entry_set_text (GTK_ENTRY (data->name), _("Multiple Files")); gtk_widget_set_sensitive (data->name, FALSE); } update_permissions (data); on_timeout (data); }