diff options
-rw-r--r-- | 0sugar/TuxPaint.activity/NEWS | 13 | ||||
-rw-r--r-- | 0sugar/TuxPaint.activity/activity/activity.info | 9 | ||||
-rw-r--r-- | 0sugar/TuxPaint.activity/activity/icon.svg | 73 | ||||
-rwxr-xr-x | 0sugar/TuxPaint.activity/setup.py | 4 | ||||
-rw-r--r-- | 0sugar/service.info | 48 | ||||
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | src/sugar.c | 207 | ||||
-rw-r--r-- | src/sugar.h | 49 | ||||
-rw-r--r-- | src/tuxpaint.c | 100 |
9 files changed, 509 insertions, 10 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ + <!ENTITY ns_svg "http://www.w3.org/2000/svg"> + <!ENTITY ns_xlink "http://www.w3.org/1999/xlink"> + <!ENTITY stroke_color "#000000"> + <!ENTITY fill_color "#AAAAAA"> +]> +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + version="1.0" + width="50" + height="50" + id="svg23699"> + <g + transform="translate(2.2795368,2.5500192)" + id="g4446"> + <path + d="M 17.127187,43.376532 C 16.055758,43.019389 14.092211,41.983376 13.621861,40.427607 C 13.295451,39.347958 12.917163,38.225465 13.376702,34.972914 C 13.648257,33.050879 14.757464,31.474464 15.519574,30.369835 L 16.318562,29.211768 C 16.318562,29.211768 14.389784,25.680946 10.51897,23.0325 C 10.51897,23.0325 8.4758522,15.614009 8.4758522,15.614009 C 8.4758522,15.614009 12.989071,12.642629 13.847113,12.703921 C 15.256756,12.489408 13.423877,16.731327 13.423877,16.731327 C 13.574018,17.436467 14.11217,17.474975 15.399238,18.608812 C 16.349208,19.360696 18.218513,20.876497 18.218513,20.876497 C 18.218513,20.876497 18.249159,18.915264 18.770114,18.087858 C 19.371128,17.073659 19.781376,16.708861 20.670065,16.095979 C 21.313594,15.758891 21.957133,15.544378 22.69259,15.360511 C 22.815175,15.05407 23.060324,8.3123078 28.208576,6.4736389 C 33.356839,4.6349803 35.318072,9.2929243 35.318072,9.2929243 C 37.892208,14.25731 37.064802,21.611965 36.819653,22.745802 C 36.697078,23.787711 37.463182,24.369958 37.463182,24.369958 C 37.463182,24.369958 44.082369,30.560119 43.530769,32.827804 C 43.775918,35.40193 40.956642,38.037348 40.466334,38.466374 C 40.405042,38.956683 40.095064,42.124763 38.071254,43.434286 L 17.127187,43.376532 z " + +style="font-size:12px;fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3.5;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23504" /> + <path + d="M 20.551936,42.861105 C 20.403653,42.790501 19.844548,42.212494 19.690752,41.865324 C 19.536956,41.518155 17.345338,38.355037 18.114326,34.960475 C 18.883315,31.565914 21.228718,32.91602 21.382524,31.411616 C 21.53632,29.907201 21.88236,28.788538 23.920173,28.557095 C 25.957996,28.325642 27.57286,29.212862 28.149604,30.717266 C 28.726348,32.221681 29.72603,35.076192 29.72603,36.387736 C 29.72603,37.69927 29.649132,40.862388 29.649132,40.862388 C 29.649132,40.862388 29.513806,42.25469 28.828615,42.816075" + +style="font-size:12px;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23514" /> + <path + d="M 10.976567,43.126565 C 13.613535,41.605552 11.143208,25.559436 9.565049,20.959802 C 9.1485887,19.273152 7.7419761,13.639765 7.7419761,13.639765 C 7.7419761,13.639765 8.9750209,10.823686 8.341352,7.9638238 C 7.4936144,4.1378303 5.3961269,4.4428542 5.5611779,1.4068893 C 5.5611779,1.4068893 3.8594947,2.8602418 3.5714737,3.5757333 C 3.2769165,4.3075092 1.966256,7.4771361 1.8465285,8.5538109 C 1.5213107,11.357893 4.1555913,14.324277 4.1555913,14.324277 C 4.1555913,14.324277 4.0990523,18.891917 4.2068152,20.118323 C 3.8152281,27.425484 10.6208,43.583506 10.976567,43.126565 z " + +style="fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3.38242745;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23530" /> + <path + d="M 8.3154767,14.058809 C 7.2963858,14.341552 4.3847683,14.497268 3.7761688,14.736506" + +style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:1.98436975;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23532" /> + <path + d="M 25.695742,9.8430418 C 26.43121,9.7204672 27.110878,10.018171 27.386673,10.477833 C 27.662468,10.937495 27.579831,10.745425 27.746737,11.613898 C 27.733052,12.069648 27.739571,12.457156 27.751091,12.566045 C 27.930604,12.734902 28.637602,9.6285296 30.813348,9.8736878 C 31.756532,9.9454934 32.692273,10.349129 32.590725,12.172018 C 32.06977,20.476643 27.631165,16.740723 27.319292,16.553602 C 26.835401,16.351697 27.084112,15.968511 26.782815,15.832282 C 26.491578,15.82142 26.483047,16.128867 26.098691,16.082359 C 25.897915,16.079597 24.990921,15.910627 24.8377,15.849335 C 24.68448,15.788053 23.458704,15.696114 23.48935,14.470339 C 23.305483,13.305855 24.085282,10.500266 25.695742,9.8430418 z " + +style="font-size:12px;fill:&stroke_color;;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:3.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23506" /> + <path + d="M 23.404475,16.087432 C 24.07865,16.056796 27.02051,16.730971 28.36886,17.680942 C 29.71721,18.630922 30.330103,20.101847 30.207529,21.266331 C 30.097593,22.283219 29.681246,24.548861 28.123711,24.943658 C 25.716019,25.515546 23.689253,24.762471 20.891631,23.687236 C 17.548588,22.414161 17.888489,15.903565 23.404475,16.087432 z " + +style="font-size:12px;fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:2.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path23510" /> + <path + d="M 30.798954,14.698748 C 30.961271,14.055137 30.730835,13.444154 30.284263,13.334084 C 29.83768,13.224004 29.344066,13.656521 29.181749,14.300132 C 29.019422,14.943733 29.249859,15.554716 29.696441,15.664796 C 30.143013,15.774866 30.636627,15.342349 30.798954,14.698748 L 30.798954,14.698748 z " + style="font-size:12px;fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke-width:1pt" + id="path23524" /> + <path + d="M 26.399896,14.243316 C 26.562213,13.451536 26.331787,12.699888 25.885205,12.564469 C 25.438622,12.429062 24.945008,12.961145 24.782691,13.752936 C 24.620364,14.544717 24.850801,15.296364 25.297383,15.431783 C 25.743955,15.567201 26.237569,15.035107 26.399896,14.243316 L 26.399896,14.243316 z " + style="font-size:12px;fill:&fill_color;;fill-opacity:1;fill-rule:evenodd;stroke-width:1pt" + id="path23622" /> + <path + d="M 21.061566,20.090535 C 20.852555,20.92655 21.047758,21.716661 21.497554,21.855303 C 21.947359,21.99395 22.481424,21.42862 22.690434,20.592604 C 22.899444,19.7566 22.704251,18.966481 22.254446,18.827836 C 21.804648,18.689202 21.270578,19.254519 21.061566,20.090535 L 21.061566,20.090535 z " + style="font-size:12px;fill:&stroke_color;;fill-opacity:1;fill-rule:evenodd;stroke-width:1pt" + id="path23624" /> + <path + d="M 35.647787,40.034689 C 37.65407,39.950738 39.29654,39.045147 39.950741,38.340559" + +style="font-size:12px;fill:none;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path851" /> + <path + d="M 33.638016,28.886874 C 33.638016,30.159245 34.122729,30.704546 34.213612,30.825724 C 34.516558,31.431614 35.9404,32.310156 35.9404,33.643115 C 35.728339,34.915485 34.940681,35.218431 34.577147,35.521376 C 34.213612,35.824321 32.196784,38.44704 34.927524,39.847794" + +style="font-size:12px;fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path854" /> + </g> +</svg> 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 @@ -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 <sys/stat.h> +#include <unistd.h> +#include <SDL/SDL_syswm.h> + +#include <polyol/env.h> +#include <polyol/ds.h> +#include <polyol/shell.h> + +#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); |