2 ptouch-gtk - Simple GTK+ UI to print labels on a Brother P-Touch
4 Copyright (C) 2015 Dominic Radermacher <dominic.radermacher@gmail.com>
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License version 3 as
8 published by the Free Software Foundation
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define BUILDER_XML_FILE "data/ptouch.ui"
29 guint statusbar_context_id;
33 void error_message(const gchar *message);
34 void on_window_destroy(GtkWidget *object, PTouchEditor *editor);
35 gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event,
36 PTouchEditor *editor);
37 gboolean init_app(PTouchEditor *editor);
39 void error_message(const gchar *message)
42 g_warning(message); /* log to terminal window */
43 /* create an error message dialog and display modally to the user */
44 dialog = gtk_message_dialog_new(NULL,
45 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
46 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message);
47 gtk_window_set_title(GTK_WINDOW(dialog), "Error!");
48 gtk_dialog_run(GTK_DIALOG(dialog));
49 gtk_widget_destroy(dialog);
52 void on_window_destroy(GtkWidget *object, PTouchEditor *editor)
57 gboolean on_window_delete_event(GtkWidget *widget, GdkEvent *event, PTouchEditor *editor)
59 return FALSE; /* propogate event */
62 void show_about(PTouchEditor *editor)
64 static const gchar * const authors[] = {
65 "Dominic Radermacher <dominic.radermacher@gmail.com>",
68 static const gchar copyright[] = "Copyright \xc2\xa9 2015 Dominic Radermacher";
69 static const gchar comments[] = "PTouch Print";
71 gtk_show_about_dialog(GTK_WINDOW(editor->window), "authors", authors,
72 "comments", comments, "copyright", copyright,
74 "website", "http://mockmoon-cybernetics.ch/",
75 "program-name", "ptouch-gtk",
76 "logo-icon-name", GTK_STOCK_EDIT, NULL);
79 gboolean init_app(PTouchEditor *editor)
85 /* use GtkBuilder to build our interface from the XML file */
86 builder = gtk_builder_new();
87 if (gtk_builder_add_from_file(builder, BUILDER_XML_FILE, &err) == 0) {
88 error_message(err->message);
92 /* get the widgets which will be referenced in callbacks */
93 editor->window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
94 editor->statusbar = GTK_WIDGET(gtk_builder_get_object(builder, "statusbar"));
95 editor->text_view = GTK_WIDGET(gtk_builder_get_object(builder, "text_view"));
96 gtk_builder_connect_signals(builder, editor);
97 /* free memory used by GtkBuilder object */
98 g_object_unref(G_OBJECT(builder));
99 gtk_window_set_default_icon_name(GTK_STOCK_EDIT);
100 /* setup and initialize our statusbar */
101 id = gtk_statusbar_get_context_id(GTK_STATUSBAR(editor->statusbar),
102 "PTouch Print GTK+");
103 editor->statusbar_context_id = id;
107 int main(int argc, char *argv[])
109 PTouchEditor *editor;
111 editor = g_slice_new(PTouchEditor);
112 gtk_init(&argc, &argv);
113 if (init_app(editor) == FALSE) {
114 return 1; /* error loading UI */
116 gtk_widget_show(editor->window);
118 g_slice_free(PTouchEditor, editor);