/* sugar.c Sugar DE integration Copyright (C) 2010, Aleksey Lim This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) */ #include #include #include #include #include #include "sugar.h" static SugarHandle * handle; static SugarJobject * jobject; static gboolean new_jobject; void sugar_init(int * argc, char *** argv) { g_type_init(); sugar_sys_set_sync_dbus(TRUE); handle = sugar_sys_parse_cmd_options(argv, argc); if (handle == NULL) return; g_debug("Use sugar mode"); if (sugar_handle_get_object_id(handle) != NULL) jobject = sugar_jobject_find(sugar_handle_get_object_id(handle)); if (jobject != NULL) g_debug("Journal entry %s was found", sugar_handle_get_object_id(handle)); else { jobject = sugar_jobject_create(sugar_handle_get_activity_id(handle)); g_debug("Create new Journal entry"); } } void sugar_cleanup() { g_debug("Cleanup sugar mode"); if (new_jobject) sugar_shell_show_object(sugar_jobject_get_uid(jobject)); if (jobject != NULL) { g_object_unref(G_OBJECT(jobject)); jobject = NULL; } if (handle != NULL) { sugar_handle_unref(handle); handle = NULL; } } void sugar_setup_x11(int * window_width, int * window_height) { if (!sugar_detected()) return; SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version); if (SDL_GetWMInfo(&wminfo)) { Display * display = wminfo.info.x11.display; Window window = wminfo.info.x11.wmwindow; wminfo.info.x11.lock_func(); sugar_sys_setup_xprops(handle, display, window); *window_width = DisplayWidth(display, DefaultScreen(display)); *window_height = DisplayHeight(display, DefaultScreen(display)); wminfo.info.x11.unlock_func(); } else { g_warning ("Cannot get WMInfo to setup X11 properties"); } } int sugar_detected() { return jobject != NULL; } char * sugar_get_jobject_file() { if (!sugar_detected()) return NULL; const char * file_path = sugar_jobject_get_file_path(jobject); if (file_path != NULL) g_debug("Load image from journal entry %s", sugar_jobject_get_uid(jobject)); return g_strdup(file_path); } void sugar_save_jobject_file(char * path) { if (!sugar_detected()) return; if (sugar_jobject_get_uid(jobject) == NULL) new_jobject |= TRUE; if (!sugar_environ_get_secure_mode()) sugar_jobject_write_file(jobject, path, TRUE); else { /* There is no way to just move files to the datastore w/o creating 0777 * directories, thus have to copy files */ sugar_jobject_write_file(jobject, path, FALSE); unlink(path); } g_debug("Saved %s image to journal entry %s", path, sugar_jobject_get_uid(jobject)); } char * sugar_get_savedir(void) { return g_strdup_printf("%s/data", sugar_environ_get_activity_root()); }