commit 04865c9e12b9d5ab3507936c554de605c79dc353 parent 7e69780bb3d18e5abe01202b3b7881548fc5be72 Author: TheJackiMonster <thejackimonster@gmail.com> Date: Thu, 23 Dec 2021 22:55:31 +0100 Added icon, desktop-file and used glib resources to load ui Signed-off-by: TheJackiMonster <thejackimonster@gmail.com> Diffstat:
34 files changed, 465 insertions(+), 95 deletions(-)
diff --git a/Makefile b/Makefile @@ -1,12 +1,14 @@ -SOURCE_DIR = src/ -INSTALL_DIR ?= /usr/local/ +RESOURCES_DIR = resources/ +SOURCE_DIR = src/ +INSTALL_DIR ?= /usr/local/ BINARY = messenger-gtk SOURCES = messenger_gtk.c\ application.c\ contact.c\ event.c\ + resources.c\ chat/messenger.c\ ui/chat.c\ ui/chat_entry.c\ @@ -23,8 +25,11 @@ SOURCES = messenger_gtk.c\ ui/profile_entry.c\ ui/send_file.c\ ui/settings.c - -HEADERS = + +HEADERS = util.h + +RESOURCES = css.gresource.xml\ + ui.gresource.xml LIBRARIES = gnunetchat PACKAGES = gnunetutil libhandy-1 gtk+-3.0 libnotify zbar libqrencode @@ -34,21 +39,43 @@ GNU_CC ?= gcc GNU_LD ?= gcc GNU_RM ?= rm -CFLAGS += -pedantic -Wall -Wextra -ggdb3 +GLIB_COMPILE_RESOURCES ?= glib-compile-resources + +CFLAGS += -pedantic -Wall -Wextra -ggdb3 -Wno-overlength-strings LDFLAGS += DEBUGFLAGS = -O0 -D _DEBUG RELEASEFLAGS = -O2 -D NDEBUG -SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) -OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) +ICON_SIZES = 32\ + 64\ + 128\ + 256\ + 512 + +APPICON_DIR = $(addprefix $(RESOURCES_DIR), icon/) + +RESOURCES_FILES = $(addprefix $(RESOURCES_DIR), $(RESOURCES)) + +SOURCE_FILES = $(RESOURCES_FILES:%.gresource.xml=%.c)\ + $(addprefix $(SOURCE_DIR), $(SOURCES)) + +RESOURCES_HEADERS = $(RESOURCES_FILES:%.gresource.xml=%.h) + HEADER_FILES = $(addprefix $(SOURCE_DIR), $(HEADERS)) + +OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) + LIBRARY_FLAGS = $(addprefix -l, $(LIBRARIES)) PACKAGE_FLAGS = $(shell pkg-config --cflags --libs $(PACKAGES)) INCLUDE_FLAGS = $(addprefix -I, $(INCLUDES)) all: $(BINARY) +%.c: %.gresource.xml + $(GLIB_COMPILE_RESOURCES) --sourcedir=$(RESOURCES_DIR) $< --generate-source + $(GLIB_COMPILE_RESOURCES) --sourcedir=$(RESOURCES_DIR) $< --generate-header + debug: CFLAGS += $(DEBUGFLAGS) debug: $(BINARY) @@ -68,16 +95,29 @@ mobile: $(BINARY) .PHONY: install +define install-icon + install -Dm644 $(addprefix $(APPICON_DIR), full_color_$(1).png) $(addprefix $(INSTALL_DIR), share/icons/hicolor/$(1)x$(1)/apps/$(BINARY).png) +endef + install: - install -m 755 $(BINARY) $(addprefix $(INSTALL_DIR), bin/) + install -Dm755 $(BINARY) $(addprefix $(INSTALL_DIR), bin/) + $(foreach SIZE,$(ICON_SIZES),$(call install-icon,$(SIZE));) + install -Dm644 $(addprefix $(RESOURCES_DIR), $(BINARY).desktop) $(addprefix $(INSTALL_DIR), share/applications/) .PHONY: uninstall +define uninstall-icon + $(GNU_RM) -f $(addprefix $(INSTALL_DIR), share/icons/hicolor/$(1)x$(1)/apps/$(BINARY).png) +endef + uninstall: $(GNU_RM) -f $(addsuffix $(BINARY), $(addprefix $(INSTALL_DIR), bin/)) + $(foreach SIZE,$(ICON_SIZES),$(call uninstall-icon,$(SIZE))) + $(GNU_RM) -f $(addsuffix $(BINARY).desktop, $(addprefix $(INSTALL_DIR), share/applications/)) .PHONY: clean clean: $(GNU_RM) -f $(BINARY) $(GNU_RM) -f $(OBJECT_FILES) + $(GNU_RM) -f $(RESOURCES_HEADERS) diff --git a/resources/.gitignore b/resources/.gitignore @@ -0,0 +1 @@ +*.h +\ No newline at end of file diff --git a/resources/css.gresource.xml b/resources/css.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnunet/Messenger-GTK"> + <file>css/style.css</file> + </gresource> +</gresources> +\ No newline at end of file diff --git a/resources/icon/full_color.svg b/resources/icon/full_color.svg @@ -0,0 +1,198 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + inkscape:export-ydpi="384.00003" + inkscape:export-xdpi="384.00003" + inkscape:export-filename="/home/thejackimonster/git/messenger-gtk/resources/icon/full_color_512.png" + sodipodi:docname="full_color.svg" + inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20, custom)" + id="svg1209" + version="1.1" + viewBox="0 0 33.866667 33.866667" + height="128" + width="128" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + <title + id="title850">Cadet-GTK Full Color Icon</title> + <defs + id="defs1203"> + <linearGradient + id="linearGradient2693" + inkscape:collect="always"> + <stop + id="stop2689" + offset="0" + style="stop-color:#cae4f5;stop-opacity:1" /> + <stop + id="stop2691" + offset="1" + style="stop-color:#ffffff;stop-opacity:1" /> + </linearGradient> + <linearGradient + id="linearGradient2685" + inkscape:collect="always"> + <stop + id="stop2681" + offset="0" + style="stop-color:#cae4f5;stop-opacity:1" /> + <stop + id="stop2683" + offset="1" + style="stop-color:#ffffff;stop-opacity:1" /> + </linearGradient> + <linearGradient + gradientUnits="userSpaceOnUse" + y2="5.9243097" + x2="17.235741" + y1="22.5128" + x1="17.037195" + id="linearGradient2687" + xlink:href="#linearGradient2685" + inkscape:collect="always" /> + <linearGradient + gradientUnits="userSpaceOnUse" + y2="5.9243097" + x2="17.235741" + y1="22.5128" + x1="17.037195" + id="linearGradient2695" + xlink:href="#linearGradient2693" + inkscape:collect="always" /> + </defs> + <sodipodi:namedview + inkscape:window-maximized="0" + inkscape:window-y="20" + inkscape:window-x="20" + inkscape:window-height="1371" + inkscape:window-width="1280" + height="128px" + units="px" + showgrid="false" + inkscape:document-rotation="0" + inkscape:current-layer="layer9" + inkscape:document-units="mm" + inkscape:cy="82.250001" + inkscape:cx="45.375" + inkscape:zoom="4" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + inkscape:pagecheckerboard="true" /> + <metadata + id="metadata1206"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title>Cadet-GTK Full Color Icon</dc:title> + <cc:license + rdf:resource="http://creativecommons.org/publicdomain/zero/1.0/" /> + <dc:date>20.06.2020</dc:date> + <dc:creator> + <cc:Agent> + <dc:title>Tobias Frisch</dc:title> + </cc:Agent> + </dc:creator> + <dc:publisher> + <cc:Agent> + <dc:title>Tobias Frisch</dc:title> + </cc:Agent> + </dc:publisher> + </cc:Work> + <cc:License + rdf:about="http://creativecommons.org/publicdomain/zero/1.0/"> + <cc:permits + rdf:resource="http://creativecommons.org/ns#Reproduction" /> + <cc:permits + rdf:resource="http://creativecommons.org/ns#Distribution" /> + <cc:permits + rdf:resource="http://creativecommons.org/ns#DerivativeWorks" /> + </cc:License> + </rdf:RDF> + </metadata> + <g + style="display:inline" + inkscape:label="speech" + id="layer7" + inkscape:groupmode="layer" + sodipodi:insensitive="true"> + <g + id="g2588" + style="stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none"> + <rect + ry="3.2343187" + y="4.2197413" + x="2.0222893" + height="25.288448" + width="29.822088" + id="rect2536-5" + style="display:inline;fill:#22af22;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" /> + <rect + style="fill:#41db41;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:stroke markers fill" + id="rect2536" + width="29.822086" + height="25.004473" + x="2.0222902" + y="3.3889046" + ry="3.1979992" /> + <path + id="path2567-3" + d="m 15.460665,29.382866 -11.7363798,3.622699 4.95e-5,-0.989758 C 8.315252,29.320779 11.753889,29.15079 15.460714,28.393108 Z" + style="display:inline;fill:#22af22;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:nodetypes="ccccc" /> + <path + style="fill:#41db41;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 15.460714,28.393108 3.7243347,32.015807 7.1226253,27.750236 Z" + id="path2567" /> + </g> + </g> + <g + inkscape:label="abstract" + id="layer8" + inkscape:groupmode="layer" + style="display:inline" + sodipodi:insensitive="true"> + <path + id="path2609" + d="m 24.212469,7.4964826 v 0.6710005 l 3.220454,1.3419431 V 8.8384257 Z" + style="fill:#22af22;fill-opacity:1;stroke:#22af22;stroke-width:0.264583px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /> + <path + sodipodi:nodetypes="ccccc" + id="path2611" + d="m 10.138688,7.4568379 -0.0043,0.5492806 -3.7016775,1.5286239 1e-7,-0.6710006 z" + style="fill:#22af22;fill-opacity:1;stroke:#22af22;stroke-width:0.264583px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1" /> + <path + style="fill:#22af22;fill-opacity:1;stroke:#22af22;stroke-width:0.265;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="m 10.022067,7.5034378 c -0.5333194,0.833367 -0.9668022,1.726601 -1.3537552,2.6477362 0.6745998,0.42663 1.3900932,0.829291 2.1975522,1.178046 0.664157,-0.111091 1.196816,-0.434828 1.747717,-0.729067 0.738694,1.148835 1.612844,2.266659 2.549213,3.37024 0.05185,0.641311 0.391592,1.444088 0.779771,2.274034 0.487043,0.08719 1.338117,0.03541 2.244909,-0.03763 0.288827,-0.847267 0.587654,-1.681769 0.810159,-2.613705 0.572787,-0.849805 1.158831,-1.68611 1.614033,-2.65565 1.320517,-0.09736 2.66522,-0.140633 3.938912,-0.342728 0.351716,-0.130912 0.745912,-0.217613 0.954731,-0.497246 -0.377639,-0.9704162 -1.182623,-2.2649688 -1.29284,-2.6009852 1.022028,0.501992 2.093066,0.951907 3.220454,1.341943 -0.438905,0.8940442 -0.76765,1.8519602 -1.08419,2.8169532 -1.346651,0.261521 -2.689009,0.540519 -4.012966,0.894441 -0.565235,0.930355 -1.023816,1.90609 -1.490516,2.878371 -0.335084,0.951673 -0.646819,1.885846 -0.949155,2.812975 -0.463826,1.090376 -0.92844,2.241624 -1.391779,3.580121 -1.068806,-0.03388 -2.123796,-0.05246 -3.084791,0.03299 C 14.81844,19.982855 14.249746,18.094645 13.583788,16.276004 13.018325,15.094653 12.493157,13.954545 11.85664,12.700466 11.308898,12.572293 10.691499,12.588294 10.070655,12.611426 9.1131819,12.031736 8.142282,11.475495 7.1612636,10.936924 6.9643046,10.234649 6.7502707,9.536547 6.4327186,8.8637418 7.7687959,8.5194338 8.9093392,8.0223058 10.022067,7.5034378 Z" + id="path2532-5" + sodipodi:nodetypes="ccccccccccccccccccccccccc" /> + <path + sodipodi:nodetypes="ccccccccccccccccccccccccc" + id="path2532" + d="M 10.022067,8.1744387 C 9.4887473,9.0078054 9.0552647,9.9010394 8.6683116,10.822174 c 0.6745998,0.42663 1.3900934,0.829291 2.1975524,1.178046 0.664157,-0.111091 1.196816,-0.434828 1.747717,-0.729067 0.738694,1.148835 1.612844,2.266659 2.549213,3.37024 0.05185,0.641311 0.391592,1.444088 0.779771,2.274034 0.487043,0.08719 1.338117,0.03541 2.244909,-0.03763 0.288827,-0.847267 0.587654,-1.681769 0.810159,-2.613705 0.572787,-0.849805 1.158831,-1.68611 1.614033,-2.65565 1.320517,-0.09736 2.66522,-0.140633 3.938912,-0.342728 0.351716,-0.130912 0.745912,-0.217613 0.954731,-0.497246 -0.377639,-0.9704156 -0.846464,-1.7639246 -1.29284,-2.6009847 1.022028,0.5019921 2.093066,0.9519071 3.220454,1.3419431 -0.438905,0.8940436 -0.76765,1.8519596 -1.08419,2.8169526 -1.346651,0.261521 -2.689009,0.540519 -4.012966,0.894441 -0.565235,0.930355 -1.023816,1.90609 -1.490516,2.878371 -0.335084,0.951673 -0.646819,1.885846 -0.949155,2.812974 -0.463826,1.090376 -0.92844,2.241625 -1.391779,3.580121 -1.068806,-0.03388 -2.123796,-0.05246 -3.084791,0.03299 C 14.81844,20.653855 14.249746,18.765644 13.583788,16.947004 13.018325,15.765653 12.493157,14.625545 11.85664,13.371466 11.308898,13.243293 10.691499,13.259294 10.070655,13.282426 9.1131817,12.702736 8.1422819,12.146495 7.1612635,11.607924 6.9643045,10.905649 6.7502706,10.207547 6.4327185,9.5347424 7.7687958,9.1904344 8.909339,8.6933064 10.022067,8.1744387 Z" + style="fill:url(#linearGradient2695);fill-opacity:1;stroke:url(#linearGradient2687);stroke-width:0.265;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </g> + <g + style="display:inline;mix-blend-mode:soft-light" + inkscape:label="light" + id="layer9" + inkscape:groupmode="layer" + sodipodi:insensitive="true"> + <path + sodipodi:nodetypes="ccccccccccccccc" + id="path2697" + d="m 7.1614078,11.61309 8.2993062,16.780017 12.402689,-0.01103 c 2.367207,0.291295 4.203301,-1.228348 3.978783,-3.794721 L 27.554263,9.4724672 c -0.457817,1.0226548 -0.759177,1.9095408 -1.08419,2.8169508 l -4.134306,0.9314 -1.490516,2.878371 -0.949155,2.812974 -1.391779,3.580121 -3.084791,0.03299 -1.835738,-5.578272 -1.727148,-3.575538 -1.785985,-0.08904 z" + style="opacity:1;fill:#aeaeae;fill-opacity:1;stroke:none;stroke-width:0.265;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </g> +</svg> diff --git a/resources/icon/full_color_128.png b/resources/icon/full_color_128.png Binary files differ. diff --git a/resources/icon/full_color_256.png b/resources/icon/full_color_256.png Binary files differ. diff --git a/resources/icon/full_color_32.png b/resources/icon/full_color_32.png Binary files differ. diff --git a/resources/icon/full_color_512.png b/resources/icon/full_color_512.png Binary files differ. diff --git a/resources/icon/full_color_64.png b/resources/icon/full_color_64.png Binary files differ. diff --git a/resources/messenger-gtk.desktop b/resources/messenger-gtk.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Version=0.0.1 +Name=Messenger-GTK +Comment=A GTK based GUI for the Messenger service of GNUnet. +TryExec=messenger-gtk +Exec=messenger-gtk +Icon=messenger-gtk +Terminal=false +StartupWMClass=MessengerGTK +Type=Application +Categories=Chat;Network;InstantMessaging;GTK;FileSharing; +MimeType=x-scheme-handler/messenger-gtk; +Keywords=messenger-gtk;chat;im;messaging;messenger;gtk; +X-GNOME-UsesNotifications=true diff --git a/resources/ui.gresource.xml b/resources/ui.gresource.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/gnunet/Messenger-GTK"> + <file compressed="true">ui/chat_entry.ui</file> + <file compressed="true">ui/chat.ui</file> + <file compressed="true">ui/contacts.ui</file> + <file compressed="true">ui/invite_contact.ui</file> + <file compressed="true">ui/message_content.ui</file> + <file compressed="true">ui/message.ui</file> + <file compressed="true">ui/message-sent.ui</file> + <file compressed="true">ui/message-status.ui</file> + <file compressed="true">ui/messenger.ui</file> + <file compressed="true">ui/new_contact.ui</file> + <file compressed="true">ui/new_group.ui</file> + <file compressed="true">ui/new_platform.ui</file> + <file compressed="true">ui/new_profile.ui</file> + <file compressed="true">ui/picker.ui</file> + <file compressed="true">ui/profile_entry.ui</file> + <file compressed="true">ui/send_file.ui</file> + <file compressed="true">ui/settings.ui</file> + </gresource> +</gresources> +\ No newline at end of file diff --git a/src/application.c b/src/application.c @@ -23,16 +23,17 @@ */ #include "application.h" +#include "resources.h" static void _load_ui_stylesheets(void) { GdkScreen* screen = gdk_screen_get_default(); GtkCssProvider* provider = gtk_css_provider_new(); - gtk_css_provider_load_from_path( + + gtk_css_provider_load_from_resource( provider, - "resources/css/style.css", - NULL + "org/gnunet/Messenger-GTK/css/style.css" ); gtk_style_context_add_provider_for_screen( @@ -65,10 +66,12 @@ application_init(MESSENGER_Application *app, hdy_init(); app->application = gtk_application_new( - "org.gnunet.MESSENGER-GTK", + "org.gnunet.Messenger-GTK", G_APPLICATION_NON_UNIQUE ); + resources_register(); + notify_init("Messenger-GTK"); app->notifications = NULL; @@ -112,6 +115,20 @@ application_init(MESSENGER_Application *app, ); } +const gchar* +application_get_resource_path(MESSENGER_Application *app, + const char *path) +{ + static gchar resource_path [PATH_MAX]; + + const gchar *base_path = g_application_get_resource_base_path( + G_APPLICATION(app->application) + ); + + snprintf(resource_path, PATH_MAX, "%s/%s", base_path, path); + return resource_path; +} + static void* _application_chat_thread(void *args) { @@ -178,6 +195,8 @@ application_run(MESSENGER_Application *app) notify_uninit(); + resources_unregister(); + g_object_unref(app->application); } diff --git a/src/application.h b/src/application.h @@ -94,6 +94,10 @@ application_init(MESSENGER_Application *app, int argc, char **argv); +const gchar* +application_get_resource_path(MESSENGER_Application *app, + const char *path); + void application_run(MESSENGER_Application *app); diff --git a/src/event.c b/src/event.c @@ -160,7 +160,7 @@ event_update_profile(MESSENGER_Application *app) hdy_avatar_set_text(ui->profile_avatar, name); gtk_label_set_text(ui->profile_label, name); - UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(); + UI_PROFILE_ENTRY_Handle *profile = ui_profile_entry_new(app); hdy_avatar_set_text(profile->entry_avatar, name); gtk_label_set_text(profile->entry_label, name); @@ -235,11 +235,7 @@ event_joining_contact(MESSENGER_Application *app, if (!handle) return; - UI_MESSAGE_Handle *message = ui_message_new( - UI_MESSAGE_STATUS, - UI_MESSAGE_CONTENT_TEXT - ); - + UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); ui_message_update(message, msg); struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( @@ -328,11 +324,7 @@ event_invitation(UNUSED MESSENGER_Application *app, if (!invitation) return; - UI_MESSAGE_Handle *message = ui_message_new( - UI_MESSAGE_STATUS, - UI_MESSAGE_CONTENT_TEXT - ); - + UI_MESSAGE_Handle *message = ui_message_new(app, UI_MESSAGE_STATUS); ui_message_update(message, msg); const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( @@ -384,15 +376,13 @@ event_receive_message(UNUSED MESSENGER_Application *app, if (!handle) return; - struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg); - const int sent = GNUNET_CHAT_message_is_sent(msg); - UI_MESSAGE_Handle *message = ui_message_new( - GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT, - file? UI_MESSAGE_CONTENT_FILE : UI_MESSAGE_CONTENT_TEXT + const UI_MESSAGE_Type type = ( + GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT ); + UI_MESSAGE_Handle *message = ui_message_new(app, type); ui_message_update(message, msg); const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( diff --git a/src/resources.c b/src/resources.c @@ -0,0 +1,44 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet 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 + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file resources.c + */ + +#include "resources.h" + +#include <gio/gio.h> + +#include "../resources/css.h" +#include "../resources/ui.h" + +void +resources_register() +{ + g_resources_register(css_get_resource()); + g_resources_register(ui_get_resource()); +} + +void +resources_unregister() +{ + g_resources_unregister(css_get_resource()); + g_resources_unregister(ui_get_resource()); +} diff --git a/src/resources.h b/src/resources.h @@ -0,0 +1,34 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet 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 + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file resources.h + */ + +#ifndef RESOURCES_H_ +#define RESOURCES_H_ + +void +resources_register(); + +void +resources_unregister(); + +#endif /* RESOURCES_H_ */ diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -279,8 +279,8 @@ ui_chat_new(MESSENGER_Application *app) handle->messages = NULL; handle->edge_value = 0; - handle->builder = gtk_builder_new_from_file( - "resources/ui/chat.ui" + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/chat.ui") ); handle->chat_box = GTK_WIDGET( @@ -466,6 +466,7 @@ ui_chat_new(MESSENGER_Application *app) } struct IterateChatGroupClosure { + MESSENGER_Application *app; GHashTable *bindings; GtkListBox *listbox; }; @@ -480,7 +481,7 @@ iterate_ui_chat_update_group_contacts(void *cls, ); GtkListBox *listbox = closure->listbox; - UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(); + UI_PROFILE_ENTRY_Handle* entry = ui_profile_entry_new(closure->app); const char *name = GNUNET_CHAT_contact_get_name(contact); @@ -559,6 +560,7 @@ ui_chat_update(UI_CHAT_Handle *handle, if (group) { struct IterateChatGroupClosure closure; + closure.app = app; closure.bindings = app->ui.bindings; closure.listbox = handle->chat_contacts_listbox; diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -35,7 +35,9 @@ ui_chat_entry_new(MESSENGER_Application *app) UI_CHAT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CHAT_ENTRY_Handle)); handle->chat = ui_chat_new(app); - handle->builder = gtk_builder_new_from_file("resources/ui/chat_entry.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/chat_entry.ui") + ); handle->entry_box = GTK_WIDGET( gtk_builder_get_object(handle->builder, "entry_box") diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c @@ -27,11 +27,13 @@ #include "../application.h" UI_CONTACT_ENTRY_Handle* -ui_contact_entry_new(void) +ui_contact_entry_new(MESSENGER_Application *app) { UI_CONTACT_ENTRY_Handle* handle = g_malloc(sizeof(UI_CONTACT_ENTRY_Handle)); - handle->builder = gtk_builder_new_from_file("resources/ui/contact_entry.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/contact_entry.ui") + ); handle->entry_box = GTK_WIDGET( gtk_builder_get_object(handle->builder, "entry_box") diff --git a/src/ui/contact_entry.h b/src/ui/contact_entry.h @@ -40,7 +40,7 @@ typedef struct UI_CONTACT_ENTRY_Handle } UI_CONTACT_ENTRY_Handle; UI_CONTACT_ENTRY_Handle* -ui_contact_entry_new(void); +ui_contact_entry_new(MESSENGER_Application *app); void ui_contact_entry_delete(UI_CONTACT_ENTRY_Handle *handle); diff --git a/src/ui/contacts.c b/src/ui/contacts.c @@ -104,7 +104,7 @@ _iterate_contacts(void *cls, const char *key = GNUNET_CHAT_contact_get_key(contact); - UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(); + UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app); gtk_list_box_prepend( app->ui.contacts.contacts_listbox, entry->entry_box @@ -139,7 +139,9 @@ ui_contacts_dialog_init(MESSENGER_Application *app, { handle->contact_entries = NULL; - handle->builder = gtk_builder_new_from_file("resources/ui/contacts.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/contacts.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "contacts_dialog") diff --git a/src/ui/invite_contact.c b/src/ui/invite_contact.c @@ -96,7 +96,7 @@ _iterate_contacts(void *cls, const char *key = GNUNET_CHAT_contact_get_key(contact); - UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(); + UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app); gtk_list_box_prepend( app->ui.invite_contact.contacts_listbox, entry->entry_box @@ -131,7 +131,9 @@ ui_invite_contact_dialog_init(MESSENGER_Application *app, { handle->contact_entries = NULL; - handle->builder = gtk_builder_new_from_file("resources/ui/invite_contact.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/invite_contact.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "invite_contact_dialog") diff --git a/src/ui/message.c b/src/ui/message.c @@ -27,8 +27,8 @@ #include "../application.h" UI_MESSAGE_Handle* -ui_message_new(UI_MESSAGE_Type type, - UI_MESSAGE_ContentType content_type) +ui_message_new(MESSENGER_Application *app, + UI_MESSAGE_Type type) { UI_MESSAGE_Handle* handle = g_malloc(sizeof(UI_MESSAGE_Handle)); @@ -39,17 +39,19 @@ ui_message_new(UI_MESSAGE_Type type, switch (handle->type) { case UI_MESSAGE_SENT: - ui_builder_file = "resources/ui/message-sent.ui"; + ui_builder_file = "ui/message-sent.ui"; break; case UI_MESSAGE_STATUS: - ui_builder_file = "resources/ui/message-status.ui"; + ui_builder_file = "ui/message-status.ui"; break; default: - ui_builder_file = "resources/ui/message.ui"; + ui_builder_file = "ui/message.ui"; break; } - handle->builder = gtk_builder_new_from_file(ui_builder_file); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, ui_builder_file) + ); handle->message_box = GTK_WIDGET( gtk_builder_get_object(handle->builder, "message_box") @@ -94,8 +96,8 @@ ui_message_new(UI_MESSAGE_Type type, gtk_builder_get_object(handle->builder, "content_box") ); - GtkBuilder *builder = gtk_builder_new_from_file( - "resources/ui/message_content.ui" + GtkBuilder *builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/message_content.ui") ); handle->timestamp_label = GTK_LABEL( @@ -131,32 +133,6 @@ ui_message_new(UI_MESSAGE_Type type, break; } - switch (content_type) - { - case UI_MESSAGE_CONTENT_TEXT: - gtk_stack_set_visible_child( - handle->content_stack, - GTK_WIDGET(handle->text_label) - ); - break; - case UI_MESSAGE_CONTENT_FILE: - gtk_stack_set_visible_child( - handle->content_stack, - GTK_WIDGET(handle->file_revealer) - ); - - gtk_revealer_set_reveal_child(handle->file_revealer, TRUE); - break; - case UI_MESSAGE_CONTENT_PREVIEW: - gtk_stack_set_visible_child( - handle->content_stack, - GTK_WIDGET(handle->preview_drawing_area) - ); - break; - default: - break; - } - gtk_container_add(content_box, GTK_WIDGET( gtk_builder_get_object(builder, "message_content_box") )); diff --git a/src/ui/message.h b/src/ui/message.h @@ -41,13 +41,6 @@ typedef enum UI_MESSAGE_Type UI_MESSAGE_STATUS = 2 } UI_MESSAGE_Type; -typedef enum UI_MESSAGE_ContentType -{ - UI_MESSAGE_CONTENT_TEXT = 0, - UI_MESSAGE_CONTENT_FILE = 1, - UI_MESSAGE_CONTENT_PREVIEW = 2 -} UI_MESSAGE_ContentType; - typedef struct UI_MESSAGE_Handle { UI_MESSAGE_Type type; @@ -75,8 +68,8 @@ typedef struct UI_MESSAGE_Handle } UI_MESSAGE_Handle; UI_MESSAGE_Handle* -ui_message_new(UI_MESSAGE_Type type, - UI_MESSAGE_ContentType content_type); +ui_message_new(MESSENGER_Application *app, + UI_MESSAGE_Type type); void ui_message_update(UI_MESSAGE_Handle *handle, diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -194,7 +194,9 @@ ui_messenger_init(MESSENGER_Application *app, { handle->chat_entries = NULL; - handle->builder = gtk_builder_new_from_file("resources/ui/messenger.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/messenger.ui") + ); handle->main_window = GTK_APPLICATION_WINDOW( gtk_builder_get_object(handle->builder, "main_window") diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c @@ -287,7 +287,9 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, handle->video = zbar_video_create(); handle->scanner = zbar_image_scanner_create(); - handle->builder = gtk_builder_new_from_file("resources/ui/new_contact.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/new_contact.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "new_contact_dialog") diff --git a/src/ui/new_group.c b/src/ui/new_group.c @@ -163,7 +163,7 @@ _iterate_contacts(void *cls, const char *key = GNUNET_CHAT_contact_get_key(contact); - UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(); + UI_CONTACT_ENTRY_Handle *entry = ui_contact_entry_new(app); gtk_list_box_prepend( app->ui.new_group.contacts_listbox, entry->entry_box @@ -198,7 +198,9 @@ ui_new_group_dialog_init(MESSENGER_Application *app, { handle->contact_entries = NULL; - handle->builder = gtk_builder_new_from_file("resources/ui/new_group.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/new_group.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "new_group_dialog") diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c @@ -100,7 +100,9 @@ void ui_new_platform_dialog_init(MESSENGER_Application *app, UI_NEW_PLATFORM_Handle *handle) { - handle->builder = gtk_builder_new_from_file("resources/ui/new_platform.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/new_platform.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "new_platform_dialog") diff --git a/src/ui/new_profile.c b/src/ui/new_profile.c @@ -77,7 +77,9 @@ void ui_new_profile_dialog_init(MESSENGER_Application *app, UI_NEW_PROFILE_Handle *handle) { - handle->builder = gtk_builder_new_from_file("resources/ui/new_profile.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/new_profile.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "new_profile_dialog") diff --git a/src/ui/picker.c b/src/ui/picker.c @@ -97,8 +97,8 @@ ui_picker_new(UNUSED MESSENGER_Application *app, { UI_PICKER_Handle *handle = g_malloc(sizeof(UI_PICKER_Handle)); - handle->builder = gtk_builder_new_from_file( - "resources/ui/picker.ui" + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/picker.ui") ); handle->picker_box = GTK_WIDGET( diff --git a/src/ui/profile_entry.c b/src/ui/profile_entry.c @@ -27,11 +27,13 @@ #include "../application.h" UI_PROFILE_ENTRY_Handle* -ui_profile_entry_new(void) +ui_profile_entry_new(MESSENGER_Application *app) { UI_PROFILE_ENTRY_Handle* handle = g_malloc(sizeof(UI_PROFILE_ENTRY_Handle)); - handle->builder = gtk_builder_new_from_file("resources/ui/profile_entry.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/profile_entry.ui") + ); handle->entry_box = GTK_WIDGET( gtk_builder_get_object(handle->builder, "entry_box") diff --git a/src/ui/profile_entry.h b/src/ui/profile_entry.h @@ -38,7 +38,7 @@ typedef struct UI_PROFILE_ENTRY_Handle } UI_PROFILE_ENTRY_Handle; UI_PROFILE_ENTRY_Handle* -ui_profile_entry_new(void); +ui_profile_entry_new(MESSENGER_Application *app); void ui_profile_entry_delete(UI_PROFILE_ENTRY_Handle *handle); diff --git a/src/ui/send_file.c b/src/ui/send_file.c @@ -231,7 +231,9 @@ void ui_send_file_dialog_init(MESSENGER_Application *app, UI_SEND_FILE_Handle *handle) { - handle->builder = gtk_builder_new_from_file("resources/ui/send_file.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/send_file.ui") + ); handle->dialog = GTK_DIALOG( gtk_builder_get_object(handle->builder, "send_file_dialog") diff --git a/src/ui/settings.c b/src/ui/settings.c @@ -37,7 +37,9 @@ void ui_settings_dialog_init(MESSENGER_Application *app, UI_SETTINGS_Handle *handle) { - handle->builder = gtk_builder_new_from_file("resources/ui/settings.ui"); + handle->builder = gtk_builder_new_from_resource( + application_get_resource_path(app, "ui/settings.ui") + ); handle->dialog = HDY_PREFERENCES_WINDOW( gtk_builder_get_object(handle->builder, "settings_dialog")