static void test_parsing(FmPathFunc func, const char* str, const char** expected, int n_expected) { GSList* elements = NULL, *l; int i; FmPath *path, *element; g_print("\ntry to parse \'%s\':\n[", str); path = func(str); for(element = path; element; element = fm_path_get_parent(element)) elements = g_slist_prepend(elements, element); for(i = 0, l = elements; l; l=l->next, ++i) { g_assert_cmpint(i, <, n_expected); element = (FmPath*)l->data; g_print("\'%s\'", fm_path_get_basename(element)); if(l->next) g_print(", "); g_assert_cmpstr(fm_path_get_basename(element), ==, expected[i]); } g_slist_free(elements); g_print("]\n"); g_assert_cmpint(i, ==, n_expected); fm_path_unref(path); }
static void test_predefined_paths() { FmPath* path; path = fm_path_new_for_uri("trash:///"); g_assert(path == fm_path_get_trash()); fm_path_unref(path); path = fm_path_new_for_uri("trash:///xxx"); g_assert(fm_path_get_parent(path) == fm_path_get_trash()); fm_path_unref(path); path = fm_path_new_for_uri("menu://"); g_assert(path == fm_path_get_apps_menu()); fm_path_unref(path); path = fm_path_new_for_uri("menu://applications"); g_assert(path == fm_path_get_apps_menu()); fm_path_unref(path); path = fm_path_new_for_uri("menu://applications/test/"); g_assert(fm_path_get_parent(path) == fm_path_get_apps_menu()); fm_path_unref(path); /* path = fm_path_new_for_path(g_get_home_dir()); g_assert(path == fm_path_get_home()); fm_path_unref(path); tmp = g_build_filename(g_get_home_dir(), "xxxx", "xx", NULL); path = fm_path_new_for_path(tmp); g_debug("path->name=%s", path->parent->parent->name); g_assert(path->parent->parent == fm_path_get_home()); fm_path_unref(path); g_free(tmp); path = fm_path_new_for_path(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP)); g_assert(path == fm_path_get_desktop()); fm_path_unref(path); tmp = g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), "xxxx", "xx", NULL); path = fm_path_new_for_path(tmp); g_assert(path->parent->parent == fm_path_get_desktop()); fm_path_unref(path); g_free(tmp); */ }
void TabPage::up() { FmPath* _path = path(); if(_path) { FmPath* parent = fm_path_get_parent(_path); if(parent) { chdir(parent, true); } } }
static void _check_native_display_names(FmPath *path) { char *path_str, *disp_name; if (path == NULL || _fm_path_get_display_name(path) != NULL) return; /* all done */ path_str = fm_path_to_str(path); disp_name = g_filename_display_basename(path_str); g_free(path_str); _fm_path_set_display_name(path, disp_name); g_free(disp_name); _check_native_display_names(fm_path_get_parent(path)); /* recursion */ }
static void _check_gfile_display_names(FmPath *path, GFile *child) { GFile *gf; GFileInfo *inf; if (path == NULL || _fm_path_get_display_name(path) != NULL) return; /* all done */ gf = g_file_get_parent(child); if (gf == NULL) /* file systems such as search:// don't support this */ return; inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME"," G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (inf != NULL) { const char *dname = g_file_info_get_edit_name(inf); if (!dname) dname = g_file_info_get_display_name(inf); _fm_path_set_display_name(path, dname); g_object_unref(inf); } _check_gfile_display_names(fm_path_get_parent(path), gf); /* recursion */ g_object_unref(gf); }
bool TabPage::canUp() { return (path() != NULL && fm_path_get_parent(path()) != NULL); }
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; }
void on_go_up(GtkAction* act, FmMainWin* win) { FmPath* parent = fm_path_get_parent(fm_folder_view_get_cwd(FM_FOLDER_VIEW(win->folder_view))); if(parent) fm_main_win_chdir( win, parent); }
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)); }
gboolean _fm_file_ops_job_move_run(FmFileOpsJob* job) { GFile *dest_dir; GFileInfo* inf; GList* l; GError* err = NULL; FmJob* fmjob = FM_JOB(job); dev_t dest_dev = 0; gboolean ret = TRUE; FmDeepCountJob* dc; FmPath *parent = NULL; FmFolder *df, *sf = NULL; /* get information of destination folder */ g_return_val_if_fail(job->dest, FALSE); dest_dir = fm_path_to_gfile(job->dest); _retry_query_dest_info: inf = g_file_query_info(dest_dir, G_FILE_ATTRIBUTE_STANDARD_IS_VIRTUAL"," G_FILE_ATTRIBUTE_UNIX_DEVICE"," G_FILE_ATTRIBUTE_ID_FILESYSTEM"," G_FILE_ATTRIBUTE_UNIX_DEVICE, 0, fm_job_get_cancellable(fmjob), &err); if(inf) { job->dest_fs_id = g_intern_string(g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_ID_FILESYSTEM)); dest_dev = g_file_info_get_attribute_uint32(inf, G_FILE_ATTRIBUTE_UNIX_DEVICE); /* needed by deep count */ g_object_unref(inf); } else { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MODERATE); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) goto _retry_query_dest_info; else { g_object_unref(dest_dir); return FALSE; } } /* prepare the job, count total work needed with FmDeepCountJob */ dc = fm_deep_count_job_new(job->srcs, FM_DC_JOB_PREPARE_MOVE); fm_deep_count_job_set_dest(dc, dest_dev, job->dest_fs_id); fm_job_run_sync(FM_JOB(dc)); job->total = dc->total_size; if( fm_job_is_cancelled(FM_JOB(dc)) ) { g_object_unref(dest_dir); g_object_unref(dc); return FALSE; } g_object_unref(dc); g_debug("total size to move: %llu, dest_fs: %s", (long long unsigned int)job->total, job->dest_fs_id); fm_file_ops_job_emit_prepared(job); /* suspend updates for destination */ df = fm_folder_find_by_path(job->dest); if (df) fm_folder_block_updates(df); for(l = fm_path_list_peek_head_link(job->srcs); !fm_job_is_cancelled(fmjob) && l; l=l->next) { FmPath* path = FM_PATH(l->data); GFile* src = fm_path_to_gfile(path); GFile* dest; char* tmp_basename; /* do with updates for source */ if (fm_path_get_parent(path) != parent && fm_path_get_parent(path) != NULL) { FmFolder *pf; pf = fm_folder_find_by_path(fm_path_get_parent(path)); if (pf != sf) { if (sf) { fm_folder_unblock_updates(sf); g_object_unref(sf); } if (pf) fm_folder_block_updates(pf); sf = pf; } else if (pf) g_object_unref(pf); } parent = fm_path_get_parent(path); if(g_file_is_native(src) && g_file_is_native(dest_dir)) /* both are native */ tmp_basename = NULL; else if(g_file_is_native(src)) /* move from native to virtual */ tmp_basename = g_filename_to_utf8(fm_path_get_basename(path), -1, NULL, NULL, NULL); /* gvfs escapes it itself */ else /* move from virtual to native/virtual */ tmp_basename = fm_uri_subpath_to_native_subpath(fm_path_get_basename(path), NULL); dest = g_file_get_child(dest_dir, tmp_basename ? tmp_basename : fm_path_get_basename(path)); g_free(tmp_basename); if(!_fm_file_ops_job_move_file(job, src, NULL, dest, path, sf, df)) ret = FALSE; g_object_unref(src); g_object_unref(dest); if(!ret) break; } /* restore updates for destination and source */ if (df) { fm_folder_unblock_updates(df); g_object_unref(df); } if (sf) { fm_folder_unblock_updates(sf); g_object_unref(sf); } g_object_unref(dest_dir); return ret; }
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); }
static void test_path_child() { FmPath* parent = fm_path_get_home(); FmPath* path; g_print("\n"); path = fm_path_new_child(parent, "child"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "child"); fm_path_unref(path); path = fm_path_new_child(parent, "child/"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "child"); fm_path_unref(path); path = fm_path_new_child(parent, "child///"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "child"); fm_path_unref(path); path = fm_path_new_child(parent, ".."); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert(path == fm_path_get_parent(parent)); fm_path_unref(path); path = fm_path_new_child(parent, "../"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert(path == fm_path_get_parent(parent)); fm_path_unref(path); path = fm_path_new_child(parent, "/"); g_assert(path == parent); fm_path_unref(path); parent = fm_path_get_root(); path = fm_path_new_child(parent, ".."); g_assert(path == parent); fm_path_unref(path); path = fm_path_new_child(parent, "../"); g_assert(path == parent); fm_path_unref(path); parent = NULL; path = fm_path_new_child(parent, "/"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "/"); fm_path_unref(path); path = fm_path_new_child(parent, "//"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "/"); fm_path_unref(path); path = fm_path_new_child(parent, "///"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "/"); fm_path_unref(path); /* FIXME: how to handle this case? path = fm_path_new_child(parent, "/test"); g_printf("path->name = %s\n", path->name); g_assert_cmpstr(path->name, ==, "/test/"); fm_path_unref(path); */ path = fm_path_new_child(parent, "trash:"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "trash:///"); fm_path_unref(path); path = fm_path_new_child(parent, "trash:/"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "trash:///"); fm_path_unref(path); path = fm_path_new_child(parent, "trash:////"); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "trash:///"); fm_path_unref(path); path = fm_path_new_child(parent, ".."); g_printf("path->name = %s\n", fm_path_get_basename(path)); g_assert_cmpstr(fm_path_get_basename(path), ==, "/"); fm_path_unref(path); path = fm_path_new_child(parent, "../"); g_assert_cmpstr(fm_path_get_basename(path), ==, "/"); fm_path_unref(path); /* path = fm_path_new_child(parent, ".."); g_assert(path == NULL); path = fm_path_new_child(parent, "."); g_assert(path == NULL); */ }