Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-05-09 23:00:16 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-05-09 23:00:16 (GMT)
commit639459e147c7b0efcbd4abd2e56a38259441e552 (patch)
tree4e06c82152d1b678ec7ba4e5e447cbfed6535f40 /src
parentaaf2912d8314141fb5e7567418f439cb50153210 (diff)
Initial sugar integration
Diffstat (limited to 'src')
-rw-r--r--src/sugar.c119
-rw-r--r--src/sugar.h46
-rw-r--r--src/tuxpaint.c92
3 files changed, 241 insertions, 16 deletions
diff --git a/src/sugar.c b/src/sugar.c
new file mode 100644
index 0000000..3b6f5aa
--- /dev/null
+++ b/src/sugar.c
@@ -0,0 +1,119 @@
+/*
+ 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)
+
+ June 14, 2002 - May 15, 2007
+ $Id: cursor.c,v 1.5 2009/11/21 09:44:11 albert Exp $
+*/
+
+#include <SDL/SDL_syswm.h>
+#include <sugar/env.h>
+#include <sugar/ds.h>
+
+#include "sugar.h"
+
+static SugarActivityHandle * handle;
+static SugarJobject * 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_activity_handle_get_object_id(handle) != NULL)
+ jobject = sugar_jobject_find(sugar_activity_handle_get_object_id(handle));
+
+ if (jobject == NULL)
+ jobject = sugar_jobject_create(
+ sugar_activity_handle_get_activity_id(handle));
+}
+
+void sugar_cleanup()
+{
+ g_debug("Cleanup sugar mode");
+
+ if (jobject != NULL) {
+ g_object_unref(G_OBJECT(jobject));
+ jobject = NULL;
+ }
+
+ if (handle != NULL) {
+ sugar_activity_handle_unref(handle);
+ handle = NULL;
+ }
+}
+
+void sugar_setup_xprops()
+{
+ if (!sugar_detected())
+ return NULL;
+
+ SDL_SysWMinfo wminfo;
+ SDL_VERSION(&wminfo.version);
+
+ if (SDL_GetWMInfo(&wminfo)) {
+ wminfo.info.x11.lock_func();
+ sugar_sys_setup_xprops(handle,
+ wminfo.info.x11.display, wminfo.info.x11.wmwindow);
+ 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;
+
+ char * file_path = NULL;
+
+ if (jobject != NULL)
+ 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;
+
+ sugar_jobject_write_file(jobject, path, TRUE);
+
+ g_debug("Saved %s image to journal entry %s", path,
+ sugar_jobject_get_uid(jobject));
+}
diff --git a/src/sugar.h b/src/sugar.h
new file mode 100644
index 0000000..4720dbf
--- /dev/null
+++ b/src/sugar.h
@@ -0,0 +1,46 @@
+/*
+ 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)
+
+ June 14, 2002 - May 15, 2007
+ $Id: cursor.h,v 1.3 2007/05/16 01:11:34 wkendrick Exp $
+*/
+
+#ifndef SUGAR_H
+#define SUGAR_H
+
+#ifdef SUGAR
+ void sugar_init(int * argc, char *** argv);
+ void sugar_cleanup(void);
+ void sugar_setup_xprops(void);
+ int sugar_detected(void);
+ char * sugar_get_jobject_file(void);
+ void sugar_save_jobject_file(char * path);
+#else
+ void sugar_init(int * argc, char *** argv) { }
+ void sugar_cleanup(void) { }
+ void sugar_setup_xprops(void) { }
+ int sugar_detected(void) { return 0; }
+ char * sugar_get_jobject_file(void) { return NULL; }
+ void sugar_save_jobject_file(char * path) { }
+#endif
+
+#endif
diff --git a/src/tuxpaint.c b/src/tuxpaint.c
index 1eded07..970bfa1 100644
--- a/src/tuxpaint.c
+++ b/src/tuxpaint.c
@@ -464,6 +464,8 @@ extern WrapperData macosx;
#include "compiler.h"
+#include "sugar.h"
+
#if VIDEO_BPP==32
#ifdef __GNUC__
@@ -980,6 +982,8 @@ static Uint8 * touched;
static int shape_radius;
+static int skip_thumbs;
+
/* Text label tool struct to hold information about text on the label layer */
typedef struct label_node
{
@@ -1522,6 +1526,7 @@ static wchar_t texttool_str[256];
static unsigned int texttool_len;
static int tool_avail[NUM_TOOLS], tool_avail_bak[NUM_TOOLS];
+static int tool_hidden[NUM_TOOLS];
static Uint32 cur_toggle_count;
@@ -1636,6 +1641,8 @@ static void playstampdesc(int chan);
#endif
static void do_wait(int counter);
static void load_current(void);
+static char * get_current_image_file(void);
+static void load_current_image(char * fname);
static void save_current(void);
static int do_prompt_image_flash(const char *const text,
const char *const btn_yes,
@@ -1763,6 +1770,7 @@ static float pick_best_scape(unsigned int orig_w, unsigned int orig_h,
#endif
static SDL_Surface * myIMG_Load(char * file);
+int tool_visible (int tool);
#define MAX_UTF8_CHAR_LENGTH 6
@@ -2615,7 +2623,7 @@ static void mainloop(void)
which = tool_scroll + GRIDHIT_GD(real_r_tools, gd_tools);
- if (which < NUM_TOOLS && tool_avail[which] &&
+ if (which < NUM_TOOLS && tool_visible(which) &&
(valid_click(event.button.button) || which == TOOL_PRINT))
{
/* Allow middle/right-click on "Print", since [Alt]+click
@@ -3993,10 +4001,10 @@ static void mainloop(void)
do_setcursor(cursor_arrow);
}
- else if (tool_avail[((event.button.x - r_tools.x) / button_w) +
+ else if (tool_visible(((event.button.x - r_tools.x) / button_w) +
((event.button.y -
r_tools.y - button_h / 2) / button_h) * gd_tools.cols +
- tool_scroll])
+ tool_scroll))
{
do_setcursor(cursor_hand);
}
@@ -4344,10 +4352,10 @@ static void mainloop(void)
do_setcursor(cursor_arrow);
}
- else if (tool_avail[((event.button.x - r_tools.x) / button_w) +
+ else if (tool_visible(((event.button.x - r_tools.x) / button_w) +
((event.button.y -
r_tools.y - button_h / 2) / button_h) * gd_tools.cols +
- tool_scroll])
+ tool_scroll))
{
do_setcursor(cursor_hand);
}
@@ -4359,9 +4367,9 @@ static void mainloop(void)
else
{
- if (tool_avail[((event.button.x - r_tools.x) / button_w) +
+ if (tool_visible(((event.button.x - r_tools.x) / button_w) +
((event.button.y -
- r_tools.y) / button_h) * gd_tools.cols])
+ r_tools.y) / button_h) * gd_tools.cols))
{
do_setcursor(cursor_hand);
}
@@ -7113,7 +7121,7 @@ static void draw_toolbar(void)
dest.y = ((i / 2) * 48) + 40 + off_y;
- if (tool < NUM_TOOLS)
+ if (tool < NUM_TOOLS && !tool_hidden[tool])
{
SDL_Surface *button_color;
SDL_Surface *button_body;
@@ -10598,7 +10606,23 @@ static void load_template(char *img_id)
static void load_current(void)
{
- SDL_Surface *tmp, *org_surf;
+ char *fname = NULL;
+
+ /* If we are in sugar mode, load from journal entry */
+ if (sugar_detected())
+ fname = sugar_get_jobject_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;
@@ -10646,7 +10670,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);
@@ -10687,9 +10719,6 @@ static void load_current(void)
load_embedded_data(fname, org_surf);
}
-
- free(fname);
- }
}
@@ -10723,6 +10752,20 @@ static void save_current(void)
char *fname;
FILE *fi;
+ if (sugar_detected())
+ {
+ if (file_id[0] != '\0')
+ {
+ char ftmp[1024];
+ snprintf(ftmp, sizeof(ftmp), "saved/%s%s",
+ file_id, FNAME_EXTENSION);
+ fname = get_fname(ftmp, DIR_SAVE);
+ sugar_save_jobject_file(fname);
+ free(fname);
+ }
+ return;
+ }
+
if (!make_directory("", "Can't create user data directory"))
{
draw_tux_text(TUX_OOPS, strerror(errno), 0);
@@ -11927,7 +11970,7 @@ static int do_save(int tool, int dont_show_success_results)
/* Make sure we have a ~/.tuxpaint/saved/.thumbs/ directory: */
- if (!make_directory("saved/.thumbs", "Can't create user data thumbnail directory"))
+ if (!skip_thumbs && !make_directory("saved/.thumbs", "Can't create user data thumbnail directory"))
{
fprintf(stderr, "Cannot save any pictures! SORRY!\n\n");
draw_tux_text(TUX_OOPS, SDL_GetError(), 0);
@@ -11977,7 +12020,8 @@ static int do_save(int tool, int dont_show_success_results)
show_progress_bar(screen);
-
+ if (!skip_thumbs)
+ {
/* Save thumbnail, too: */
/* (Was thumbnail in old directory, rather than under .thumbs?) */
@@ -12018,6 +12062,7 @@ static int do_save(int tool, int dont_show_success_results)
SDL_FreeSurface(thm);
free(fname);
+ }
#if 0 /* No more writing the .dat file */
/* Write 'starter' and/or canvas color info, if it's useful to: */
@@ -20769,6 +20814,8 @@ static void setup(void)
}
}
+ // sugar X properties should be set before the window is shown on the screen
+ sugar_setup_xprops();
#ifndef NOSOUND
#ifndef WIN32
@@ -21713,6 +21760,11 @@ static void claim_to_be_ready(void)
draw_tux_text(tool_tux[cur_tool], tool_tips[cur_tool], 1);
}
+int tool_visible (int tool)
+{
+ return tool_avail[tool] && !tool_hidden[tool];
+}
+
////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
@@ -21721,7 +21773,7 @@ int main(int argc, char *argv[])
CLOCK_TYPE time2;
CLOCK_TYPE time3;
- (void)argc;
+ sugar_init(&argc, &argv);
CLOCK_ASM(time1);
@@ -21730,6 +21782,13 @@ int main(int argc, char *argv[])
chdir_to_binary(argv[0]);
setup_config(argv);
+ if (sugar_detected()) {
+ tool_hidden[TOOL_OPEN] = 1;
+ tool_hidden[TOOL_SAVE] = 1;
+ autosave_on_quit = 1;
+ promptless_save = SAVE_OVER_NO;
+ skip_thumbs = 1;
+ }
@@ -21765,5 +21824,6 @@ int main(int argc, char *argv[])
save_current();
wait_for_sfx();
cleanup();
+ sugar_cleanup();
return 0;
}