/* ColorCombinate (c) Iago Rubio, */ #include #include #define CC_APP_TITLE "ColorCombinate" /* Color Combinate callbacks */ void cc_colorcombinate_palette_changed (GtkWidget *widget, gpointer user_data) { gchar *text, *file; file = cc_get_palette_filename (CC_COLORCOMBINATE_DIALOG(widget)); if( !file ) text = g_strdup (CC_APP_TITLE); else text = g_strdup_printf ("%s: %s", CC_APP_TITLE, file); gtk_window_set_title (GTK_WINDOW(widget), text); if( file ) g_free (file); g_free (text); } void cc_colorcombinate_response (GtkDialog *dialog, gint arg1, gpointer user_data) { gtk_widget_destroy (GTK_WIDGET(dialog)); gtk_main_quit(); } /* application stuff */ void cc_parse_args (GtkWidget *dialog, int *argc, char **argv[], GError **error) { GOptionContext* context; static gboolean collapsed = FALSE; static gboolean dontsave = FALSE; static gchar *file = NULL; static gchar** files = NULL; static GOptionEntry entries[] = { { "collapsed", 'c', 0, G_OPTION_ARG_NONE, &collapsed, "Show in 'palette view' mode, with all widgets collapsed", NULL }, { "dontsave", 'd', 0, G_OPTION_ARG_NONE, &dontsave, "Don't show the file open/save buttons", NULL }, { "file", 'f', 0, G_OPTION_ARG_STRING, &file, "Open this GIMP palette file (full path)", NULL }, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files, "Open this GIMP palette file (full path)", NULL}, { NULL } }; context = g_option_context_new ("- show the color combinate application"); g_option_context_add_main_entries (context, entries, "colorcombinate"); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, argc, argv, error); g_option_context_free (context); if( *error ) return; if( collapsed ){ g_object_set (G_OBJECT(dialog), "color_expanded", FALSE, "combination_expanded", FALSE, "scheme_expanded", FALSE, NULL ); } if( dontsave ){ g_object_set (G_OBJECT(dialog), "open_files", FALSE, NULL ); } if( file ){ cc_load_palette (CC_COLORCOMBINATE_DIALOG(dialog), file, error); } if( files ){ if( !file ) cc_load_palette (CC_COLORCOMBINATE_DIALOG(dialog), *files, error); g_strfreev(files); } if( file ) g_free (file); } int main (int argc, char *argv[]) { GtkWidget *dialog; GError *error = NULL; gtk_set_locale (); gtk_init (&argc, &argv); dialog = cc_colorcombinate_dialog_new(); gtk_window_set_type_hint (GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_NORMAL); cc_parse_args (dialog, &argc, &argv, &error); if( error ){ g_warning ("%s", error->message); g_error_free (error); } g_signal_connect ( dialog, "response", G_CALLBACK (cc_colorcombinate_response), NULL ); g_signal_connect (dialog, "palette_changed", G_CALLBACK (cc_colorcombinate_palette_changed), NULL ); gtk_window_set_title (GTK_WINDOW (dialog), CC_APP_TITLE); gtk_widget_show (GTK_WIDGET(dialog)); gtk_main (); return 0; }