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"
"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)
endif()
@ -173,11 +178,6 @@ function(vala_precompile output)
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")
# 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)
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")

View file

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

View file

@ -1,13 +1,11 @@
using Gtk;
using Dino.Entities;
public class Dino.Application : Gtk.Application {
public interface Dino.Application : GLib.Application {
public Database db;
public StreamInteractor stream_interaction;
public Plugins.Registry plugin_registry = new Plugins.Registry();
public SearchPathGenerator? search_path_generator { get; set; }
public abstract Database db { get; set; }
public abstract StreamInteractor stream_interaction { get; set; }
public abstract Plugins.Registry plugin_registry { get; set; }
public abstract SearchPathGenerator? search_path_generator { get; set; }
static string print_xmpp;
@ -16,7 +14,7 @@ public class Dino.Application : Gtk.Application {
{ null }
};
public Application() throws Error {
public void init() throws Error {
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());
}

View file

@ -1,5 +1,3 @@
using Gtk;
using Dino.Entities;
namespace Dino.Plugins {
@ -12,6 +10,10 @@ public enum Priority {
HIGHEST
}
public enum WidgetType {
GTK
}
public interface RootInterface : Object {
public abstract void registered(Dino.Application app);
@ -31,10 +33,10 @@ public abstract class AccountSettingsEntry : Object {
public abstract string name { get; }
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 signal void activated();
@ -42,24 +44,30 @@ public interface AccountSettingsWidget : Gtk.Widget {
public abstract void deactivate();
}
public abstract class ContactDetailsProvider : Object {
public interface ContactDetailsProvider : Object {
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 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 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);
}

View file

@ -31,7 +31,7 @@ public class AvatarManager : StreamInteractionModule, Object {
}
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) {

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")]
public static extern unowned string _(string s);

View file

@ -3,11 +3,17 @@ using Gtk;
using Dino.Entities;
using Dino.Ui;
public class Dino.Ui.Application : Dino.Application {
public class Dino.Ui.Application : Gtk.Application, Dino.Application {
private Notifications notifications;
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 {
init();
Notify.init("dino");
Environment.set_application_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));
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(() => {
@ -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));
}
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);
ListBoxRow list_row = new ListBoxRow() { activatable=false, visible=true };

View file

@ -6,15 +6,16 @@ using Xmpp.Xep;
namespace Dino.Ui.ContactDetails {
public class MucConfigFormProvider : Plugins.ContactDetailsProvider {
public override string id { get { return "muc_config_form"; } }
public class MucConfigFormProvider : Plugins.ContactDetailsProvider, Object {
public string id { get { return "muc_config_form"; } }
private StreamInteractor stream_interactor;
public MucConfigFormProvider(StreamInteractor 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) {
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
if (stream == null) return;

View file

@ -4,8 +4,8 @@ using Dino.Entities;
namespace Dino.Ui.ContactDetails {
public class SettingsProvider : Plugins.ContactDetailsProvider {
public override string id { get { return "chat_settings"; } }
public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
public string id { get { return "chat_settings"; } }
private StreamInteractor stream_interactor;
@ -13,7 +13,8 @@ public class SettingsProvider : Plugins.ContactDetailsProvider {
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) {
ComboBoxText[] comboboxes = new ComboBoxText[2];
for (int i = 0; i < 3; i++) {

View file

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

View file

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

View file

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

View file

@ -25,9 +25,11 @@ public class ConversationTitlebar : Gtk.HeaderBar {
app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor, window));
foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget();
widgets.add(widget);
pack_end(widget);
Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
widgets.add(widget);
pack_end((Gtk.Widget)widget);
}
}
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;
Application app = GLib.Application.get_default() as Application;
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);
widget.visible = true;
Label label = new Label(e.name) { xalign=1, yalign=0, visible=true };
label.get_style_context().add_class("dim-label");
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(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++;
}
}

View file

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

View file

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

View file

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

View file

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