libdino: remove dependency to GTK+ (all GTK+ code is in main+plugins)

This commit is contained in:
Marvin W 2017-05-04 22:05:48 +02:00
parent f78818abbe
commit 5dc460fc1a
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
19 changed files with 115 additions and 69 deletions

View file

@ -118,7 +118,12 @@ function(vala_precompile output)
cmake_parse_arguments(ARGS "FAST_VAPI" "DIRECTORY;GENERATE_HEADER;GENERATE_VAPI;EXPORTS_DIR" cmake_parse_arguments(ARGS "FAST_VAPI" "DIRECTORY;GENERATE_HEADER;GENERATE_VAPI;EXPORTS_DIR"
"SOURCES;PACKAGES;OPTIONS;DEFINITIONS;CUSTOM_VAPIS;CUSTOM_DEPS;GRESOURCES" ${ARGN}) "SOURCES;PACKAGES;OPTIONS;DEFINITIONS;CUSTOM_VAPIS;CUSTOM_DEPS;GRESOURCES" ${ARGN})
if("Ninja" STREQUAL ${CMAKE_GENERATOR} AND NOT DISABLE_FAST_VAPI) # Header and internal header is needed to generate internal vapi
if (ARGS_GENERATE_VAPI AND NOT ARGS_GENERATE_HEADER)
set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI})
endif(ARGS_GENERATE_VAPI AND NOT ARGS_GENERATE_HEADER)
if("Ninja" STREQUAL ${CMAKE_GENERATOR} AND NOT DISABLE_FAST_VAPI AND NOT ARGS_GENERATE_HEADER)
set(ARGS_FAST_VAPI true) set(ARGS_FAST_VAPI true)
endif() endif()
@ -173,11 +178,6 @@ function(vala_precompile output)
list(APPEND out_extra_files "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}_internal.vapi") list(APPEND out_extra_files "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}_internal.vapi")
set(vapi_arguments "--vapi=${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.vapi" "--internal-vapi=${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}_internal.vapi") set(vapi_arguments "--vapi=${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.vapi" "--internal-vapi=${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}_internal.vapi")
# Header and internal header is needed to generate internal vapi
if (NOT ARGS_GENERATE_HEADER)
set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI})
endif(NOT ARGS_GENERATE_HEADER)
if(ARGS_PACKAGES) if(ARGS_PACKAGES)
string(REPLACE ";" "\\n" pkgs "${ARGS_PACKAGES};${ARGS_CUSTOM_DEPS}") string(REPLACE ";" "\\n" pkgs "${ARGS_PACKAGES};${ARGS_CUSTOM_DEPS}")
add_custom_command(OUTPUT "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.deps" COMMAND echo -e "\"${pkgs}\"" > "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.deps" COMMENT "Generating ${ARGS_GENERATE_VAPI}.deps") add_custom_command(OUTPUT "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.deps" COMMAND echo -e "\"${pkgs}\"" > "${ARGS_EXPORTS_DIR}/${ARGS_GENERATE_VAPI}.deps" COMMENT "Generating ${ARGS_GENERATE_VAPI}.deps")

View file

@ -1,9 +1,9 @@
find_packages(LIBDINO_PACKAGES REQUIRED find_packages(LIBDINO_PACKAGES REQUIRED
GDKPixbuf2
Gee Gee
GLib GLib
GModule GModule
GObject GObject
GTK3
) )
vala_precompile(LIBDINO_VALA_C vala_precompile(LIBDINO_VALA_C

View file

@ -1,13 +1,11 @@
using Gtk;
using Dino.Entities; using Dino.Entities;
public class Dino.Application : Gtk.Application { public interface Dino.Application : GLib.Application {
public Database db; public abstract Database db { get; set; }
public StreamInteractor stream_interaction; public abstract StreamInteractor stream_interaction { get; set; }
public Plugins.Registry plugin_registry = new Plugins.Registry(); public abstract Plugins.Registry plugin_registry { get; set; }
public SearchPathGenerator? search_path_generator { get; set; } public abstract SearchPathGenerator? search_path_generator { get; set; }
static string print_xmpp; static string print_xmpp;
@ -16,7 +14,7 @@ public class Dino.Application : Gtk.Application {
{ null } { null }
}; };
public Application() throws Error { public void init() throws Error {
if (DirUtils.create_with_parents(get_storage_dir(), 0700) == -1) { if (DirUtils.create_with_parents(get_storage_dir(), 0700) == -1) {
throw new Error(-1, 0, "Could not create storage dir \"%s\": %s", get_storage_dir(), FileUtils.error_from_errno(errno).to_string()); throw new Error(-1, 0, "Could not create storage dir \"%s\": %s", get_storage_dir(), FileUtils.error_from_errno(errno).to_string());
} }

View file

@ -1,5 +1,3 @@
using Gtk;
using Dino.Entities; using Dino.Entities;
namespace Dino.Plugins { namespace Dino.Plugins {
@ -12,6 +10,10 @@ public enum Priority {
HIGHEST HIGHEST
} }
public enum WidgetType {
GTK
}
public interface RootInterface : Object { public interface RootInterface : Object {
public abstract void registered(Dino.Application app); public abstract void registered(Dino.Application app);
@ -31,10 +33,10 @@ public abstract class AccountSettingsEntry : Object {
public abstract string name { get; } public abstract string name { get; }
public virtual int16 label_top_padding { get { return -1; } } public virtual int16 label_top_padding { get { return -1; } }
public abstract AccountSettingsWidget get_widget(); public abstract AccountSettingsWidget? get_widget(WidgetType type);
} }
public interface AccountSettingsWidget : Gtk.Widget { public interface AccountSettingsWidget : Object {
public abstract void set_account(Account account); public abstract void set_account(Account account);
public abstract signal void activated(); public abstract signal void activated();
@ -42,24 +44,30 @@ public interface AccountSettingsWidget : Gtk.Widget {
public abstract void deactivate(); public abstract void deactivate();
} }
public abstract class ContactDetailsProvider : Object { public interface ContactDetailsProvider : Object {
public abstract string id { get; } public abstract string id { get; }
public abstract void populate(Conversation conversation, ContactDetails contact_details); public abstract void populate(Conversation conversation, ContactDetails contact_details, WidgetType type);
} }
public class ContactDetails : Object { public class ContactDetails : Object {
public signal void save(); public signal void save();
public signal void add(string category, string label, string? desc, Widget widget); public signal void add(string category, string label, string? desc, Object widget);
} }
public abstract class ConversationTitlebarEntry : Object { public interface TextCommand : Object {
public abstract string cmd { get; }
public abstract string? handle_command(string? text, Entities.Conversation? conversation);
}
public interface ConversationTitlebarEntry : Object {
public abstract string id { get; } public abstract string id { get; }
public abstract double order { get; } public abstract double order { get; }
public abstract ConversationTitlebarWidget get_widget(); public abstract ConversationTitlebarWidget get_widget(WidgetType type);
} }
public interface ConversationTitlebarWidget : Gtk.Widget { public interface ConversationTitlebarWidget : Object {
public abstract void set_conversation(Conversation conversation); public abstract void set_conversation(Conversation conversation);
} }

View file

@ -31,7 +31,7 @@ public class AvatarManager : StreamInteractionModule, Object {
} }
public static string get_storage_dir() { public static string get_storage_dir() {
return Path.build_filename(Application.get_storage_dir(), "avatars"); return Path.build_filename(Dino.get_storage_dir(), "avatars");
} }
private AvatarManager(StreamInteractor stream_interactor, Database db) { private AvatarManager(StreamInteractor stream_interactor, Database db) {

View file

@ -20,6 +20,10 @@ public class SearchPathGenerator {
} }
} }
public static string get_storage_dir() {
return Path.build_filename(Environment.get_user_data_dir(), "dino");
}
[CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")] [CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")]
public static extern unowned string _(string s); public static extern unowned string _(string s);

View file

@ -3,11 +3,17 @@ using Gtk;
using Dino.Entities; using Dino.Entities;
using Dino.Ui; using Dino.Ui;
public class Dino.Ui.Application : Dino.Application { public class Dino.Ui.Application : Gtk.Application, Dino.Application {
private Notifications notifications; private Notifications notifications;
private UnifiedWindow window; private UnifiedWindow window;
public Database db { get; set; }
public StreamInteractor stream_interaction { get; set; }
public Plugins.Registry plugin_registry { get; set; default = new Plugins.Registry(); }
public SearchPathGenerator? search_path_generator { get; set; }
public Application() throws Error { public Application() throws Error {
init();
Notify.init("dino"); Notify.init("dino");
Environment.set_application_name("Dino"); Environment.set_application_name("Dino");
Gtk.Window.set_default_icon_name("dino"); Gtk.Window.set_default_icon_name("dino");

View file

@ -45,7 +45,7 @@ public class Dialog : Gtk.Dialog {
app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor)); app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor));
foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) { foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) {
provider.populate(conversation, contact_details); provider.populate(conversation, contact_details, Plugins.WidgetType.GTK);
} }
destroy.connect(() => { destroy.connect(() => {
@ -72,7 +72,9 @@ public class Dialog : Gtk.Dialog {
Util.image_set_from_scaled_pixbuf(avatar, (new AvatarGenerator(50, 50, avatar.scale_factor)).draw_conversation(stream_interactor, conversation)); Util.image_set_from_scaled_pixbuf(avatar, (new AvatarGenerator(50, 50, avatar.scale_factor)).draw_conversation(stream_interactor, conversation));
} }
private void add_entry(string category, string label, string? description, Widget w) { private void add_entry(string category, string label, string? description, Object wo) {
if (!(wo is Widget)) return;
Widget w = (Widget) wo;
add_category(category); add_category(category);
ListBoxRow list_row = new ListBoxRow() { activatable=false, visible=true }; ListBoxRow list_row = new ListBoxRow() { activatable=false, visible=true };

View file

@ -6,15 +6,16 @@ using Xmpp.Xep;
namespace Dino.Ui.ContactDetails { namespace Dino.Ui.ContactDetails {
public class MucConfigFormProvider : Plugins.ContactDetailsProvider { public class MucConfigFormProvider : Plugins.ContactDetailsProvider, Object {
public override string id { get { return "muc_config_form"; } } public string id { get { return "muc_config_form"; } }
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
public MucConfigFormProvider(StreamInteractor stream_interactor) { public MucConfigFormProvider(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
} }
public override void populate(Conversation conversation, Plugins.ContactDetails contact_details) { public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) {
if (type != Plugins.WidgetType.GTK) return;
if (conversation.type_ == Conversation.Type.GROUPCHAT) { if (conversation.type_ == Conversation.Type.GROUPCHAT) {
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account); Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
if (stream == null) return; if (stream == null) return;

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Ui.ContactDetails { namespace Dino.Ui.ContactDetails {
public class SettingsProvider : Plugins.ContactDetailsProvider { public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
public override string id { get { return "chat_settings"; } } public string id { get { return "chat_settings"; } }
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
@ -13,7 +13,8 @@ public class SettingsProvider : Plugins.ContactDetailsProvider {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
} }
public override void populate(Conversation conversation, Plugins.ContactDetails contact_details) { public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) {
if (type != Plugins.WidgetType.GTK) return;
if (conversation.type_ == Conversation.Type.CHAT) { if (conversation.type_ == Conversation.Type.CHAT) {
ComboBoxText[] comboboxes = new ComboBoxText[2]; ComboBoxText[] comboboxes = new ComboBoxText[2];
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {

View file

@ -5,13 +5,16 @@ using Dino.Entities;
namespace Dino.Ui { namespace Dino.Ui {
class EncryptionEntry : Plugins.ConversationTitlebarEntry { class EncryptionEntry : Plugins.ConversationTitlebarEntry, Object {
public override string id { get { return "encryption"; } } public string id { get { return "encryption"; } }
public override double order { get { return 2; } } public double order { get { return 2; } }
public override Plugins.ConversationTitlebarWidget get_widget() { public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) {
return new EncryptionWidget() { visible=true }; return new EncryptionWidget() { visible=true };
} }
return null;
}
} }
class EncryptionWidget : MenuButton, Plugins.ConversationTitlebarWidget { class EncryptionWidget : MenuButton, Plugins.ConversationTitlebarWidget {

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Ui { namespace Dino.Ui {
class MenuEntry : Plugins.ConversationTitlebarEntry { class MenuEntry : Plugins.ConversationTitlebarEntry, Object {
public override string id { get { return "menu"; } } public string id { get { return "menu"; } }
StreamInteractor stream_interactor; StreamInteractor stream_interactor;
@ -13,10 +13,13 @@ class MenuEntry : Plugins.ConversationTitlebarEntry {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
} }
public override double order { get { return 0; } } public double order { get { return 0; } }
public override Plugins.ConversationTitlebarWidget get_widget() { public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) {
return new MenuWidget(stream_interactor) { visible=true }; return new MenuWidget(stream_interactor) { visible=true };
} }
return null;
}
} }
class MenuWidget : MenuButton, Plugins.ConversationTitlebarWidget { class MenuWidget : MenuButton, Plugins.ConversationTitlebarWidget {

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Ui { namespace Dino.Ui {
class OccupantsEntry : Plugins.ConversationTitlebarEntry { class OccupantsEntry : Plugins.ConversationTitlebarEntry, Object {
public override string id { get { return "occupants"; } } public string id { get { return "occupants"; } }
StreamInteractor stream_interactor; StreamInteractor stream_interactor;
Window window; Window window;
@ -15,10 +15,13 @@ class OccupantsEntry : Plugins.ConversationTitlebarEntry {
this.window = window; this.window = window;
} }
public override double order { get { return 3; } } public double order { get { return 3; } }
public override Plugins.ConversationTitlebarWidget get_widget() { public Plugins.ConversationTitlebarWidget get_widget(Plugins.WidgetType type) {
if (type == Plugins.WidgetType.GTK) {
return new OccupantsWidget(stream_interactor, window) { visible=true }; return new OccupantsWidget(stream_interactor, window) { visible=true };
} }
return null;
}
} }
class OccupantsWidget : MenuButton, Plugins.ConversationTitlebarWidget { class OccupantsWidget : MenuButton, Plugins.ConversationTitlebarWidget {

View file

@ -25,9 +25,11 @@ public class ConversationTitlebar : Gtk.HeaderBar {
app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor, window)); app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor, window));
foreach(var e in app.plugin_registry.conversation_titlebar_entries) { foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget(); Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
widgets.add(widget); widgets.add(widget);
pack_end(widget); pack_end((Gtk.Widget)widget);
}
} }
stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => {

View file

@ -56,16 +56,22 @@ public class Dialog : Gtk.Dialog {
int16 default_top_padding = new Gtk.Button().get_style_context().get_padding(Gtk.StateFlags.NORMAL).top + 1; int16 default_top_padding = new Gtk.Button().get_style_context().get_padding(Gtk.StateFlags.NORMAL).top + 1;
Application app = GLib.Application.get_default() as Application; Application app = GLib.Application.get_default() as Application;
foreach (var e in app.plugin_registry.account_settings_entries) { foreach (var e in app.plugin_registry.account_settings_entries) {
Plugins.AccountSettingsWidget widget = e.get_widget(); Plugins.AccountSettingsWidget widget = e.get_widget(Plugins.WidgetType.GTK);
plugin_widgets.add(widget); plugin_widgets.add(widget);
widget.visible = true;
Label label = new Label(e.name) { xalign=1, yalign=0, visible=true }; Label label = new Label(e.name) { xalign=1, yalign=0, visible=true };
label.get_style_context().add_class("dim-label"); label.get_style_context().add_class("dim-label");
label.set_padding(0, e.label_top_padding == -1 ? default_top_padding : e.label_top_padding); label.set_padding(0, e.label_top_padding == -1 ? default_top_padding : e.label_top_padding);
settings_list.attach(label, 0, row_index); settings_list.attach(label, 0, row_index);
settings_list.attach(widget, 1, row_index, 2); if (widget is Widget) {
Widget gtkw = (Widget) widget;
plugin_widgets.add(widget);
gtkw.visible = true;
settings_list.attach(gtkw, 1, row_index, 2);
} else {
// TODO
}
row_index++; row_index++;
} }
} }

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Plugins.HttpFiles { namespace Dino.Plugins.HttpFiles {
public class ConversationsTitlebarEntry : Plugins.ConversationTitlebarEntry { public class ConversationsTitlebarEntry : Plugins.ConversationTitlebarEntry, Object {
public override string id { get { return "send_files"; } } public string id { get { return "send_files"; } }
StreamInteractor stream_interactor; StreamInteractor stream_interactor;
@ -13,10 +13,13 @@ public class ConversationsTitlebarEntry : Plugins.ConversationTitlebarEntry {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
} }
public override double order { get { return 4; } } public double order { get { return 4; } }
public override Plugins.ConversationTitlebarWidget get_widget() { public Plugins.ConversationTitlebarWidget get_widget(WidgetType type) {
if (type == WidgetType.GTK) {
return new ConversationTitlebarWidget(stream_interactor) { visible=true }; return new ConversationTitlebarWidget(stream_interactor) { visible=true };
} }
return null;
}
} }
public class ConversationTitlebarWidget : Button, Plugins.ConversationTitlebarWidget { public class ConversationTitlebarWidget : Button, Plugins.ConversationTitlebarWidget {

View file

@ -15,9 +15,12 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
return "OMEMO"; return "OMEMO";
}} }}
public override Plugins.AccountSettingsWidget get_widget() { public override Plugins.AccountSettingsWidget? get_widget(WidgetType type) {
if (type == WidgetType.GTK) {
return new AccountSettingWidget(plugin); return new AccountSettingWidget(plugin);
} }
return null;
}
} }
} }

View file

@ -16,9 +16,12 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
return "OpenPGP"; return "OpenPGP";
}} }}
public override Plugins.AccountSettingsWidget get_widget() { public override Plugins.AccountSettingsWidget? get_widget(WidgetType type) {
if (type == WidgetType.GTK) {
return new AccountSettingsWidget(plugin); return new AccountSettingsWidget(plugin);
} }
return null;
}
} }
} }

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Plugins.OpenPgp { namespace Dino.Plugins.OpenPgp {
public class ContactDetailsProvider : Plugins.ContactDetailsProvider { public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
public override string id { get { return "pgp_info"; } } public string id { get { return "pgp_info"; } }
private StreamInteractor stream_interactor; private StreamInteractor stream_interactor;
@ -13,8 +13,8 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider {
this.stream_interactor = stream_interactor; this.stream_interactor = stream_interactor;
} }
public override void populate(Conversation conversation, Plugins.ContactDetails contact_details) { public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) {
if (conversation.type_ == Conversation.Type.CHAT) { if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) {
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
if (key_id != null) { if (key_id != null) {
Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id); Gee.List<GPG.Key> keys = GPGHelper.get_keylist(key_id);