ctb_actions.h File Reference

#include <glib.h>
#include "filemodel.h"
Include dependency graph for ctb_actions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

G_BEGIN_DECLS int activate_item (const filelist_entry_t *fileinfo)
 activate: launch viewer, goto directory, ...
int delete_item (const filelist_entry_t *fileinfo)
 delete: delete file or directory
int create_shortcut_item (const filelist_entry_t *fileinfo)
 shortcut: create shortcut on desktop for file or directory

Function Documentation

G_BEGIN_DECLS int activate_item ( const filelist_entry_t fileinfo  ) 

activate: launch viewer, goto directory, ...

File Name : ctb_actions.h

Description: Content browser actions on selected file(s) or directory(ies) Copyright (C) 2008 iRex Technologies B.V. All rights reserved.---------------------------------------------------------------------------

Name : activate_item

Parameters:
[in] fileinfo - details of the item
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 229 of file ctb_actions.c.

References activate_shortcut(), filelist_entry_t::directory_path, ER_FAIL, ER_OK, ERRORPRINTF, filename, filelist_entry_t::filename, filelist_entry_t::filename_display, filelist_entry_t::filetype, fileview_dir_down(), fileview_stop_update_display(), get_viewer_from_file_extension(), handle_special_item(), ipc_sys_start_task(), filelist_entry_t::is_directory, is_shortcut_file_extension(), show_error_dialog(), and SPECIAL_ITEM_NAME.

Referenced by activate_shortcut(), and handle_activate_item().

00230 {
00231     g_assert(item);
00232     g_assert(item->directory_path   && item->directory_path->str);
00233     g_assert(item->filename         && item->filename->str        );
00234 
00235     const gchar *filetype = item->filetype->str;
00236     if (strcmp(filetype, SPECIAL_ITEM_NAME) == 0) {
00237         handle_special_item(item);
00238         return ER_OK;
00239     }
00240 
00241     const gchar *filename  = item->filename->str;
00242     const gchar *directory = item->directory_path->str;
00243     if (item->is_directory)
00244     {
00245         fileview_stop_update_display();
00246         char fullname[512];
00247         sprintf(fullname, "%s/%s", directory, filename);
00248         fileview_dir_down(fullname, filename);
00249         return ER_OK;
00250     }
00251 
00252     if (is_shortcut_file_extension(filetype))
00253     {
00254         return activate_shortcut(item);
00255     }
00256 
00257     // normal file, start viewer
00258     const gchar *viewer_cmd = get_viewer_from_file_extension(filetype);
00259     if (viewer_cmd == NULL)
00260     {
00261         gchar *error_msg = g_strdup_printf( _("'%s' cannot be opened; the format is unknown."),
00262                                      filename);
00263         show_error_dialog(error_msg);
00264         g_free(error_msg);
00265         return ER_FAIL;
00266     }
00267 
00268     gchar *cmd_line = g_strdup_printf("%s \"%s/%s\"", viewer_cmd, directory, filename);
00269     gchar *ret_message = NULL;
00270     gint errcode = ipc_sys_start_task(cmd_line, directory,
00271                                       item->filename_display->str, NULL, &ret_message);
00272     if (errcode > 0 && ret_message && ret_message[0] != '\0')
00273     {
00274         ERRORPRINTF("cannot launch viewer, cmd_line [%s], errcode %d [%s]", cmd_line, errcode, ret_message);
00275         show_error_dialog(ret_message);
00276     }
00277 #if MACHINE_IS_DR800S || MACHINE_IS_DR800SG || MACHINE_IS_DR800SW
00278     else if (errcode == 0) filemodel_update_last_read(item);
00279 #endif
00280 
00281     g_free(ret_message);
00282     g_free(cmd_line);
00283     return ER_OK;
00284 }

Here is the call graph for this function:

Here is the caller graph for this function:

int create_shortcut_item ( const filelist_entry_t fileinfo  ) 

shortcut: create shortcut on desktop for file or directory

---------------------------------------------------------------------------

Name : create_shortcut_item

Parameters:
[in] fileinfo - details of the item
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 370 of file ctb_actions.c.

References cp, create_shortcut_file(), DIR_SHORTCUTS, filelist_entry_t::directory_path, ER_FORBIDDEN, ER_OK, ermetadb_global_add_file(), ERRORPRINTF, filemodel_get_database(), filelist_entry_t::filename, filelist_entry_t::filename_display, filelist_entry_t::filetype, ipc_get_media(), shortcut_allowed(), shortcut_dir, and show_error_dialog().

Referenced by fileview_create_shortcut().

00371 {
00372     g_assert(item);
00373     g_assert(item->filename          && item->filename->str        );
00374     g_assert(item->filename_display  && item->filename_display->str);
00375     g_assert(item->filetype          && item->filetype->str        );
00376     g_assert(item->directory_path    && item->directory_path->str  );
00377 
00378     if (!shortcut_allowed(item)) {
00379         gchar *error_msg = g_strdup_printf(_("A shortcut cannot be created for this item"));
00380         show_error_dialog(error_msg);
00381         g_free(error_msg);
00382         return ER_FORBIDDEN;
00383     }
00384 
00385     const gchar *mountpoint = ipc_get_media();
00386     char shortcut_dir[256];
00387     sprintf(shortcut_dir, "%s/%s", mountpoint, DIR_SHORTCUTS);
00388 
00389     // create shortcut dir if it doesn't exist
00390     g_mkdir_with_parents (shortcut_dir, 644);
00391 
00392     // create shortcut file on disk
00393     const gchar *target_dir = item->directory_path->str;
00394     const gchar *target_file = item->filename->str;
00395     const gchar *target_display = item->filename_display->str;
00396     GString *shortcut_file = g_string_new("");
00397     int ret = create_shortcut_file(target_dir, target_file, target_display, shortcut_dir, shortcut_file);
00398     if (ret != ER_OK) {
00399         ERRORPRINTF("cannot create shortcut for %s/%s", target_dir, target_file);
00400         g_string_free(shortcut_file, TRUE);
00401         return ret;
00402     }
00403 
00404     // add to metadb
00405     erMetadb db = filemodel_get_database();
00406     gint64 now = time(NULL);
00407     char subtitle[512];
00408     // NOTE: assumes shortcut is created on mountpoint, skip
00409     snprintf(subtitle, 512, "%s/%s", target_dir + strlen(mountpoint), target_file);
00410     subtitle[sizeof(subtitle)-1] = 0;
00411     char* cp = subtitle;
00412     if (subtitle[0] == '/') cp++;
00413     ret = ermetadb_global_add_file(db, shortcut_dir, shortcut_file->str, 0, now, target_display, cp, "");
00414     if (ret != ER_OK) {
00415         ERRORPRINTF("cannot add %s/%s to metadb", shortcut_dir, shortcut_file->str);
00416     }
00417 
00418     g_string_free(shortcut_file, TRUE);
00419     return ret;
00420 }

Here is the call graph for this function:

Here is the caller graph for this function:

int delete_item ( const filelist_entry_t fileinfo  ) 

delete: delete file or directory

---------------------------------------------------------------------------

Name : delete_item

Parameters:
[in] fileinfo - details of the item
Returns:
ER_OK or error code

--------------------------------------------------------------------------

Definition at line 298 of file ctb_actions.c.

References delete_item_from_db(), filelist_entry_t::directory_path, ER_FAIL, ER_OK, ERRORPRINTF, filemodel_get_database(), filename, filelist_entry_t::filename, filelist_entry_t::filetype, get_viewer_from_file_extension(), ipc_sys_stop_task(), and LOGPRINTF.

Referenced by delete_entry_at_offset().

00299 {
00300     g_assert(item);
00301     g_assert(item->filename          && item->filename->str        );
00302     g_assert(item->filetype          && item->filetype->str        );
00303     g_assert(item->directory_path    && item->directory_path->str  );
00304 
00305     const gchar *filename = item->filename->str;
00306     const gchar *filetype = item->filetype->str;
00307 
00308     LOGPRINTF( "entry: filename [%s] dirpath [%s]", filename, item->directory_path->str);
00309 
00310     // tell sysd to close document, then wait for a reply from sysd
00311     gchar *filepath = g_strdup_printf("%s/%s", item->directory_path->str, filename);
00312 
00313     const gchar *viewer_cmd = get_viewer_from_file_extension(filetype);
00314     if (viewer_cmd)
00315     {
00316         gchar *cmd_line = g_strdup_printf("%s \"%s\"", viewer_cmd, filepath);
00317         ipc_sys_stop_task(cmd_line);
00318         g_free(cmd_line);
00319     }
00320 
00321     // remove file or directory from FS
00322     const char *argv[10];
00323     unsigned int argc = 0;
00324     argv[argc++] = "rm";
00325     argv[argc++] = "-fr";
00326     argv[argc++] = filepath;
00327     argv[argc++] = NULL;
00328     g_assert(argc < sizeof(argv)/sizeof(argv[0]));
00329     gint stat;
00330     GError *err = NULL;
00331     gboolean ok = g_spawn_sync( NULL,          // working directory: inherit
00332                        (char**)argv,           // child's argument vector
00333                        NULL,                   // environment: inherit
00334                        G_SPAWN_SEARCH_PATH,    // flags
00335                        NULL,                   // child_setup: none
00336                        NULL,                   // child setup data: none
00337                        NULL,                   // stdout: not interested
00338                        NULL,                   // stderr: not interested
00339                        &stat,                  // exit status
00340                        &err                );  // error return
00341     g_free(filepath);
00342     if (!ok)
00343     {
00344         ERRORPRINTF("g_spawn_sync error [%s] on delete [%s/%s]",
00345                 err->message, item->directory_path->str, filename);
00346         g_clear_error(&err);
00347         return ER_FAIL;
00348     }
00349 
00350     delete_item_from_db(filemodel_get_database(), item);
00351     return ER_OK;
00352 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208