Skip to content

Commit

Permalink
Added Backup/export feature
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Jul 1, 2014
1 parent 7b905f1 commit dfa2bae
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace Venom {
} catch (Error e) {
string message = _("Could not read theme from \"%s\"").printf(ResourceFactory.instance.default_theme_filename);
Logger.log(LogLevel.ERROR, message);
UITools.ErrorDialog(message, e.message, this);
UITools.show_error_dialog(message, e.message, this);
return;
}

Expand Down Expand Up @@ -235,6 +235,9 @@ namespace Venom {
(menuitem_status_busy.image as Gtk.Image).set_from_pixbuf(ResourceFactory.instance.busy);
(menuitem_status_offline.image as Gtk.Image).set_from_pixbuf(ResourceFactory.instance.offline);

Gtk.MenuItem menuitem_export = builder.get_object("menuitem_export") as Gtk.MenuItem;
Gtk.MenuItem menuitem_import = builder.get_object("menuitem_import") as Gtk.MenuItem;

Gtk.ImageMenuItem menuitem_about = builder.get_object("menuitem_about") as Gtk.ImageMenuItem;
Gtk.ImageMenuItem menuitem_quit = builder.get_object("menuitem_quit") as Gtk.ImageMenuItem;

Expand Down Expand Up @@ -291,6 +294,8 @@ namespace Venom {
// Workaround for gtk+ 3.4 MenuItems not deriving from Gtk.Actionable
menuitem_copy_id.activate.connect( () => {application.activate_action("copy-id", null);});
menuitem_edit_info.activate.connect(() => {activate_action("edit-user", null);});
menuitem_export.activate.connect(() => {UITools.export_datafile(this, session);});
menuitem_import.activate.connect(() => {UITools.import_datafile(this, session);});
menuitem_about.activate.connect(() => {application.activate_action("about", null);});
menuitem_quit.activate.connect( () => {application.activate_action("quit", null);});

Expand Down Expand Up @@ -1154,7 +1159,7 @@ namespace Venom {
stripped_id = resolved_id;
} else {
Logger.log(LogLevel.ERROR, "Could not resolve ID from DNS record");
UITools.ErrorDialog(_("Resolving ID failed"), _("Could not resolve ID from DNS record\n"), this);
UITools.show_error_dialog(_("Resolving ID failed"), _("Could not resolve ID from DNS record\n"), this);
return false;
}
}
Expand All @@ -1164,7 +1169,7 @@ namespace Venom {
// add friend
if(contact_id == null || contact_id.length != Tox.FRIEND_ADDRESS_SIZE) {
Logger.log(LogLevel.INFO, "Could not add friend: Invalid ID");
UITools.ErrorDialog(_("Adding Friend failed"), _("Could not add friend: Invalid ID\n"), this);
UITools.show_error_dialog(_("Adding Friend failed"), _("Could not add friend: Invalid ID\n"), this);
return false;
}
Contact c = new Contact(contact_id);
Expand All @@ -1175,7 +1180,7 @@ namespace Venom {
Tox.FriendAddError ret = session.add_friend(c, contact_message);
if(ret < 0) {
Logger.log(LogLevel.ERROR, "Could not add friend: %s.".printf(Tools.friend_add_error_to_string(ret)));
UITools.ErrorDialog(_("Adding Friend failed"), _("Could not add friend: %s.\n").printf(Tools.friend_add_error_to_string(ret)), this);
UITools.show_error_dialog(_("Adding Friend failed"), _("Could not add friend: %s.\n").printf(Tools.friend_add_error_to_string(ret)), this);
return false;
}

Expand Down
35 changes: 34 additions & 1 deletion src/ui/UITools.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Venom {
public class UITools : GLib.Object {
public static void ErrorDialog(string message, string? secondary_text = null, Gtk.Window? parent = null) {
public static void show_error_dialog(string message, string? secondary_text = null, Gtk.Window? parent = null) {
Gtk.MessageDialog dialog = new Gtk.MessageDialog(
parent,
Gtk.DialogFlags.MODAL,
Expand Down Expand Up @@ -113,6 +113,39 @@ namespace Venom {
return menu;
}

public static void export_datafile(Gtk.Window parent, ToxSession s) {
Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog(
_("Export tox data file"),
parent,
Gtk.FileChooserAction.SAVE,
"_Cancel",
Gtk.ResponseType.CANCEL,
"_Save",
Gtk.ResponseType.ACCEPT
);
dialog.set_filename(ResourceFactory.instance.data_filename);
dialog.transient_for = parent;
int ret = dialog.run();
string filename = dialog.get_filename();
dialog.destroy();

if(ret != Gtk.ResponseType.ACCEPT) {
return;
}
Logger.log(LogLevel.INFO, "Exporting data file to " + filename);
try {
s.save_to_file(filename);
} catch (GLib.Error e) {
Logger.log(LogLevel.ERROR, "Could not export data file: " + e.message);
show_error_dialog(_("Exporting data file failed"), _("Could not export data file: ") + e.message, parent);
}
}

public static void import_datafile(Gtk.Window parent, ToxSession s) {
//TODO
show_error_dialog(_("Importing data files is currently not supported"), "", parent);
}

#if ENABLE_QR_ENCODE
public static Gdk.Pixbuf? qr_encode(string content) {
QR.Code code = QR.Code.encode_string(content, 0, QR.ECLevel.M, QR.Mode.EIGHT_BIT, false);
Expand Down
28 changes: 28 additions & 0 deletions src/ui/contact_list.ui
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@
</child>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="menuitem_separator1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem_export">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">E_xport data file</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem_import">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes">_Import data file</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="menutitem_separator2">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menuitem_about">
<property name="label">gtk-about</property>
Expand Down

0 comments on commit dfa2bae

Please sign in to comment.