From 61d348bc25d8b0f1a82344f38f4cc1d4a90bb2b7 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Thu, 10 Jun 2010 06:21:17 +0000 Subject: Initial sugar support --- diff --git a/0sugar/TuxPaint.activity/NEWS b/0sugar/TuxPaint.activity/NEWS new file mode 100644 index 0000000..481b461 --- /dev/null +++ b/0sugar/TuxPaint.activity/NEWS @@ -0,0 +1,13 @@ +v4 2010-05-12 +~~~~~~~~~~~~~ +* Update tuxpaint to 0.9.22 version +* Initial Journal integration +* Tuxpaint without stamp to make bundle as minimal as possible + stamps will be added as optional dependency after implementing + this feature in 0install + +v3 2009-05-31 +~~~~~~~~~~~~~ +* Pick up existed TuxPaint bundle +* Update tuxpaint to 0.9.20 version +* Include x86_64 binaries to bundle diff --git a/0sugar/TuxPaint.activity/activity/activity.info b/0sugar/TuxPaint.activity/activity/activity.info new file mode 100644 index 0000000..6051ae0 --- /dev/null +++ b/0sugar/TuxPaint.activity/activity/activity.info @@ -0,0 +1,9 @@ +[Activity] +name = Tux Paint +bundle_id = org.tuxpaint +license = GPLv2 +icon = icon +exec = .0sugar/launch tuxpaint --nolockfile +activity_version = 4 +mime_types = image/png +requires = tuxpaint diff --git a/0sugar/TuxPaint.activity/activity/icon.svg b/0sugar/TuxPaint.activity/activity/icon.svg new file mode 100644 index 0000000..cf7ed1d --- /dev/null +++ b/0sugar/TuxPaint.activity/activity/icon.svg @@ -0,0 +1,73 @@ + + + + + + +]> + + + + + + + + + + + + + + + diff --git a/0sugar/TuxPaint.activity/setup.py b/0sugar/TuxPaint.activity/setup.py new file mode 100755 index 0000000..9fe7f6d --- /dev/null +++ b/0sugar/TuxPaint.activity/setup.py @@ -0,0 +1,4 @@ +#!/bin/env python + +from sugar.activity import bundlebuilder +bundlebuilder.start() diff --git a/0sugar/service.info b/0sugar/service.info new file mode 100644 index 0000000..aa47581 --- /dev/null +++ b/0sugar/service.info @@ -0,0 +1,48 @@ +[DEFAULT] +uid = tuxpaint +summary = Drawing program designed for young children +license = GPLv2 +homepage = http://www.tuxpaint.org/ + +[Service] +category = Education;Art +icon = data/images/tuxpaint-icon.svg +requires = libpaper, librsvg, cairo, fribidi + sdl, sdl-image, sdl-mixer, sdl-ttf, sdl-pango + env, ds, shell +binding = PATH bin + TUXPAINT_DATA_PREFIX share/tuxpaint + TUXPAINT_LOCALEDIR share/locale + TUXPAINT_MAGIC_PREFIX lib/tuxpaint/plugins +recipe = bin, data + +[data] +exclude = bin/*, lib/* + +[bin] +main = bin/tuxpaint +include = bin/*, lib/* +arch = build + +[Build] +requires = libpaper/devel, librsvg/devel, cairo/devel, fribidi/devel, sdl/devel + sdl-image/devel, sdl-mixer/devel, sdl-ttf/devel, sdl-pango/devel + env/devel, ds/devel, shell/devel + pkgconfig, make, gcc-c +exec = cd "$SRCDIR" && + make PREFIX=/ SUGAR=1 OPTFLAGS="$CFLAGS -I$PAPER_PATH/include" + PAPER_LIB="-L$PAPER_PATH/lib -lpaper" && + make PREFIX=/ SUGAR=1 DESTDIR="$DISTDIR" install + +[Maintain] +exec = version=$(echo $(grep ^VER_VERSION Makefile | awk -F= '{print $2}')) && + test "$version" && + rm -rf .0sugar/tuxpaint-$version && + mkdir -p .0sugar/tuxpaint-$version/obj && + find . -follow \( -wholename '*/CVS' -o -name .thumbs + -o -name .cvsignore -o -name 'dummy.o' -o -name 'build' + -o -name '.#*' -o -name obj -o -name '*.mo' -o -path ./tuxpaint + -o -name '*.tar.*' -o -name .git -o -name .0sugar \) -prune + -o -type f + -exec cp --parents -dp {} .0sugar/tuxpaint-$version/ \; && + tar cjpf tuxpaint-$version.tar.bz2 -C .0sugar tuxpaint-$version diff --git a/Makefile b/Makefile index 1c891f6..535dcf5 100644 --- a/Makefile +++ b/Makefile @@ -194,6 +194,10 @@ NOSVGFLAG:=$(if $(SVG_LIB),,-DNOSVG$(warning No SVG for you!)) # SVG support uses libcairo1 OLDSVGFLAG:=$(if $(filter -lsvg-cairo,$(SVG_LIB)),-DOLD_SVG,) +# Sugar DE support +SUGAR_CFLAGS = $(if $(SUGAR), $(shell $(PKG_CONFIG) --cflags polyol-ds polyol-shell)) +SUGAR_LIBS = $(if $(SUGAR), $(shell $(PKG_CONFIG) --libs polyol-ds polyol-shell)) +SUGAR_OBJS = $(if $(SUGAR), obj/sugar.o) ifeq ($(hack),1) hack: @@ -226,7 +230,7 @@ DEFS:=-DVER_DATE=\"$(VER_DATE)\" -DVER_VERSION=\"$(VER_VERSION)\" \ -DCONFDIR=\"$(patsubst $(DESTDIR)%,%,$(CONFDIR))/\" \ -DDEFAULT_MAGIC_PREFIX=\"$(patsubst $(DESTDIR)%,%,$(MAGIC_PREFIX))/\" \ $(NOSOUNDFLAG) $(NOSVGFLAG) $(OLDSVGFLAG) $(NOPANGOFLAG) \ - $(MAEMOFLAG) + $(MAEMOFLAG) $(if $(SUGAR), -DSUGAR) DEBUG_FLAGS:= #DEBUG_FLAGS:=-g @@ -911,13 +915,13 @@ install-man: tuxpaint: obj/tuxpaint.o obj/i18n.o obj/im.o obj/cursor.o obj/pixels.o \ obj/rgblinear.o obj/playsound.o obj/fonts.o obj/parse.o \ - obj/progressbar.o obj/dirwalk.o obj/get_fname.o \ + obj/progressbar.o obj/dirwalk.o obj/get_fname.o $(SUGAR_OBJS) \ $(ARCH_LIBS) @echo @echo "...Linking Tux Paint..." $(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SDL_CFLAGS) $(FRIBIDI_CFLAGS) $(DEFS) \ -o tuxpaint $^ \ - $(SDL_LIBS) $(SVG_LIB) $(ARCH_LINKS) + $(SDL_LIBS) $(SVG_LIB) $(ARCH_LINKS) $(SUGAR_LIBS) @$(RSRC_CMD) @$(MIMESET_CMD) @@ -932,6 +936,7 @@ obj/tuxpaint.o: src/tuxpaint.c \ src/tools.h src/titles.h src/colors.h src/shapes.h \ src/sounds.h src/tip_tux.h src/great.h \ src/tp_magic_api.h src/parse.h \ + src/sugar.h \ src/$(MOUSEDIR)/arrow.xbm src/$(MOUSEDIR)/arrow-mask.xbm \ src/$(MOUSEDIR)/hand.xbm src/$(MOUSEDIR)/hand-mask.xbm \ src/$(MOUSEDIR)/insertion.xbm \ @@ -1059,6 +1064,11 @@ obj/resource.o: win32/resources.rc win32/resource.h @echo "...Compiling win32 resources..." @$(WINDRES) -i win32/resources.rc -o obj/resource.o +obj/sugar.o: src/sugar.c src/sugar.h + @echo + @echo "...Compiling sugar support..." + @$(CC) $(CFLAGS) $(DEBUG_FLAGS) $(SUGAR_CFLAGS) $(DEFS) \ + -c src/sugar.c -o obj/sugar.o src/tp_magic_api.h: src/tp_magic_api.h.in @echo diff --git a/src/sugar.c b/src/sugar.c new file mode 100644 index 0000000..a3cd78b --- /dev/null +++ b/src/sugar.c @@ -0,0 +1,207 @@ +/* + 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 + +#include "sugar.h" + +static void chooser_response_cb(GObject*, const gchar*); + +static SugarShell *shell; +static SugarJournal *journal; +static SugarJobject *jobject; +static gboolean new_jobject; +static GMainLoop *chooser_loop; +static char *chosen_object_id; + +void sugar_setup(int * argc, char *** argv) +{ + g_type_init(); + + if (!sugar_init(argv, argc)) + return; + + g_debug("Use sugar mode"); + + sugar_environ_set_sync_dbus(TRUE); + + if (sugar_environ_get_object_id() != NULL) + jobject = sugar_jobject_find(sugar_environ_get_object_id()); + + if (jobject != NULL) + g_debug("Journal entry %s was found", sugar_environ_get_object_id()); + else + { + jobject = sugar_jobject_create(); + g_debug("Create new Journal entry"); + } + + shell = sugar_shell_new(); + + journal = sugar_journal_new(); + g_signal_connect(journal, "chooser-response", + G_CALLBACK(chooser_response_cb), NULL); + + chooser_loop = g_main_loop_new (NULL, FALSE); +} + +int sugar_detected() +{ + return sugar_environ_get_initialized(); +} + +void sugar_cleanup() +{ + if (!sugar_detected()) + return; + + g_debug("Cleanup sugar mode"); + + if (new_jobject) + sugar_journal_show_object(journal, sugar_jobject_get_uid(jobject)); + + g_object_unref(G_OBJECT(jobject)); + jobject = NULL; + + g_object_unref(G_OBJECT(shell)); + shell = NULL; + + g_object_unref(G_OBJECT(journal)); + journal = NULL; + + g_main_loop_unref(chooser_loop); + chooser_loop = 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_environ_set_window(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"); + } +} + +const char *sugar_get_savedir(void) +{ + return sugar_environ_get_activity_root(); +} + +char *sugar_get_image_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_image(char *path) +{ + if (!sugar_detected()) + return; + + if (sugar_jobject_get_uid(jobject) == NULL) + new_jobject |= TRUE; + + sugar_jobject_set_mime_type(jobject, "image/png"); + sugar_jobject_write_file(jobject, path, TRUE); + + g_debug("Saved %s image to journal entry %s", path, + sugar_jobject_get_uid(jobject)); +} + +void sugar_save_thumb(char *path) +{ + struct stat fstat; + g_return_if_fail(stat(path, &fstat) == 0); + + FILE *fp = fopen(path, "rb"); + g_return_if_fail(fp); + + GArray *preview = g_array_new(FALSE, FALSE, 1); + g_array_set_size(preview, fstat.st_size); + + if (fread(preview->data, 1, fstat.st_size, fp) == (size_t) fstat.st_size) + { + sugar_jobject_set_preview(jobject, preview); + sugar_jobject_write(jobject); + } + + fclose(fp); + unlink(path); +} + +const char *sugar_open() +{ + sugar_journal_choose_object(journal, SUGAR_MIME_IMAGE); + g_main_loop_run(chooser_loop); + + if (chosen_object_id == NULL) + return NULL; + + SugarJobject *image_jobject = sugar_jobject_find(chosen_object_id); + g_free(chosen_object_id); + chosen_object_id = NULL; + g_return_val_if_fail(image_jobject, NULL); + + const char *image_path = sugar_jobject_get_file_path(image_jobject); + g_return_val_if_fail(image_path, NULL); + + return g_strdup(image_path); +} + +static void chooser_response_cb(GObject *sender, const gchar *object_id) +{ + g_debug("SugarShell.chooser_response_cb=%s", object_id); + chosen_object_id = g_strdup(object_id); + g_main_loop_quit(chooser_loop); +} diff --git a/src/sugar.h b/src/sugar.h new file mode 100644 index 0000000..bacd387 --- /dev/null +++ b/src/sugar.h @@ -0,0 +1,49 @@ +/* + sugar.h + + 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) +*/ + +#ifndef SUGAR_H +#define SUGAR_H + +#ifdef SUGAR + void sugar_setup(int * argc, char *** argv); + void sugar_cleanup(void); + void sugar_setup_x11(int * window_width, int * window_height); + int sugar_detected(void); + const char *sugar_get_savedir(void); + char *sugar_get_image_file(void); + void sugar_save_image(char *path); + void sugar_save_thumb(char *path); + const char *sugar_open(void); +#else + void sugar_setup(int * argc, char *** argv) { } + void sugar_cleanup(void) { } + void sugar_setup_x11(int * window_width, int * window_height) { } + int sugar_detected(void) { return 0; } + const char *sugar_get_savedir(void) { return NULL; } + char *sugar_get_image_file(void) { return NULL; } + void sugar_save_image(char *path) { } + void sugar_save_thumb(char *path) { } + const char *sugar_open(void) { return NULL; } +#endif + +#endif diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 6d271b3..6fafaf3 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -463,6 +463,7 @@ extern WrapperData macosx; #include "compiler.h" +#include "sugar.h" #include "tuxpaint.h" @@ -1734,6 +1735,7 @@ Bytef * get_chunk_data (FILE * fp, char *fname, png_structp png_ptr, static void get_new_file_id(void); static int do_quit(int tool); static int do_open(void); +static int do_open_image(void); static int do_new_dialog(void); static int do_color_picker(void); static int do_slideshow(void); @@ -10713,7 +10715,22 @@ static void load_template(char *img_id) static void load_current(void) { - SDL_Surface *tmp, *org_surf; + char *fname = NULL; + + if (sugar_detected()) + fname = sugar_get_image_file(); + else + fname = get_current_image_file(); + + if (fname != NULL) + load_current_image(fname); + + free(fname); +} + +static char * get_current_image_file(void) +{ + char *result = NULL; char *fname; char ftmp[1024]; FILE *fi; @@ -10761,7 +10778,15 @@ static void load_current(void) snprintf(ftmp, sizeof(ftmp), "saved/%s%s", file_id, FNAME_EXTENSION); - fname = get_fname(ftmp, DIR_SAVE); + result = get_fname(ftmp, DIR_SAVE); + } + + return result; +} + +static void load_current_image(char * fname) +{ + SDL_Surface *tmp, *org_surf; tmp = IMG_Load(fname); @@ -10802,9 +10827,6 @@ static void load_current(void) load_embedded_data(fname, org_surf); } - - free(fname); - } } @@ -12087,6 +12109,8 @@ static int do_save(int tool, int dont_show_success_results) } } + if (sugar_detected()) + sugar_save_image(fname); free(fname); @@ -12132,6 +12156,8 @@ static int do_save(int tool, int dont_show_success_results) } SDL_FreeSurface(thm); + if (sugar_detected()) + sugar_save_thumb(fname); free(fname); #if 0 /* No more writing the .dat file */ @@ -12175,6 +12201,10 @@ static int do_save(int tool, int dont_show_success_results) } undo_tmp_applied_text(); + + if (sugar_detected()) + /* In sugar, files are not stored in savedir, thus no need in file_id */ + file_id[0] = '\0'; return 1; } @@ -12818,6 +12848,50 @@ static int do_quit(int tool) static int do_open(void) { + if (sugar_detected()) + { + const char *fname = sugar_open(); + if (fname) + { + do_setcursor(cursor_watch); + SDL_Flip(screen); + show_progress_bar(screen); + SDL_UpdateRect(screen, 0, 0, 0, 0); + SDL_Flip(screen); + + free_surface(&img_starter); + free_surface(&img_starter_bkgd); + starter_id[0] = '\0'; + template_id[0] = '\0'; + starter_mirrored = 0; + starter_flipped = 0; + starter_personal = 0; + starter_modified = 0; + canvas_color_r = canvas_color_g = canvas_color_b = 255; + + SDL_Surface *tmp, *org_surf; + tmp = IMG_Load(fname); + org_surf = SDL_DisplayFormat(tmp); + autoscale_copy_smear_free(tmp, canvas, SDL_BlitSurface); + load_embedded_data(fname, org_surf); + free(fname); + + cur_undo = 0; + oldest_undo = 0; + newest_undo = 0; + been_saved = 1; + tool_avail_bak[TOOL_UNDO] = 0; + tool_avail_bak[TOOL_REDO] = 0; + + update_canvas(0, 0, canvas->w, canvas->h); + } + } else { + do_open_image(); + } +} + +static int do_open_image(void) +{ SDL_Surface *img, *img1, *img2, *org_surf; int things_alloced; SDL_Surface **thumbs = NULL; @@ -18081,7 +18155,7 @@ static int do_new_dialog(void) if (!been_saved && !disable_save) { - if (do_prompt_image_snd(PROMPT_OPEN_SAVE_TXT, + if (!sugar_detected() && do_prompt_image_snd(PROMPT_OPEN_SAVE_TXT, PROMPT_OPEN_SAVE_YES, PROMPT_OPEN_SAVE_NO, img_tools[TOOL_SAVE], NULL, NULL, @@ -20816,7 +20890,7 @@ static void do_lock_file(void) /* (Make sure the directory exists, first!) */ homedirdir = get_fname("", DIR_SAVE); - mkdir(homedirdir, 0755); + mkdir(homedirdir, 0775); free(homedirdir); @@ -20936,6 +21010,9 @@ static void setup(void) } } + // sugar X properties should be set before the window is shown on the screen + if (sugar_detected()) + sugar_setup_x11(&WINDOW_WIDTH, &WINDOW_HEIGHT); #ifndef NOSOUND #ifndef WIN32 @@ -21915,6 +21992,8 @@ int main(int argc, char *argv[]) if (envdir) LOCALEDIR = localedir_realpath = realpath(envdir, NULL); + sugar_setup(&argc, &argv); + CLOCK_ASM(time1); // do not add code (slowness) here unless required for scanning fonts @@ -21922,6 +22001,12 @@ int main(int argc, char *argv[]) chdir_to_binary(argv[0]); setup_config(argv); + if (sugar_detected()) { + savedir = sugar_get_savedir(); + /* With saving to Sugar Journal, only followed settings make sense */ + promptless_save = SAVE_OVER_ALWAYS; + autosave_on_quit = 1; + } @@ -21957,6 +22042,7 @@ int main(int argc, char *argv[]) save_current(); wait_for_sfx(); cleanup(); + sugar_cleanup(); free(data_prefix_realpath); free(magic_prefix_realpath); -- cgit v0.9.1