Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vaults states check #9

Closed
wants to merge 13 commits into from
24 changes: 24 additions & 0 deletions resources/ui/CryptorWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use-underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImageMenuItem" id="mi_refresh">
<property name="label">gtk-refresh</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
<signal name="activate" handler="on_mi_refresh_activate" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
Expand Down
17 changes: 16 additions & 1 deletion src/data/Vault.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ namespace Cryptor.Data {
public string mount_point { get; set; }
public string mode { get; set; }
public bool reverse { get; set; }
public bool is_mounted;
public bool is_mounted () {
string cmd = "mountpoint -q " + this.mount_point;
bool result = false;
string standard_error;
int status;
try {
Process.spawn_command_line_sync (cmd, null, out standard_error, out status);
} catch (Error e) {
throw e;
} finally {
if (status == 0) {
result = true;
}
}
return result;
}
}
}
25 changes: 15 additions & 10 deletions src/ui/CryptorWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ namespace Cryptor.UI {
win.show_all ();
}

[GtkCallback]
private void on_mi_refresh_activate (Gtk.MenuItem mi) {
sync_treeview_from_conf ();
}

[GtkCallback]
private bool on_tree_view_button_press (Widget w, Gdk.EventButton e) {
if (e.button == Gdk.BUTTON_SECONDARY) {
Expand Down Expand Up @@ -201,6 +206,7 @@ namespace Cryptor.UI {
this.hide ();
} else {
this.show_all ();
sync_treeview_from_conf ();
}
} else if (ev.button == 3) {
var menu = new Gtk.Menu ();
Expand All @@ -211,6 +217,7 @@ namespace Cryptor.UI {
this.hide ();
} else {
this.show_all ();
sync_treeview_from_conf ();
}
});
menu.append (show);
Expand All @@ -234,22 +241,20 @@ namespace Cryptor.UI {
return;
}

if (!vault.is_mounted) {
if (!vault.is_mounted ()) {
var password = Utils.show_password_entry (this, false, false);
if (password == null) {
return;
}
try {
Gocrypt.mount_vault (vault.path, vault.mount_point, password, (vault.mode == "r"), vault.reverse);
vault.is_mounted = true;
sync_treeview_from_conf ();
} catch (Error e) {
if (e.message.contains ("fusermount exited with code 256")) {
if (Utils.show_question (this, "%s\n\n%s\n%s".printf (e.message, _("Vault might be mounted already."), _("Shall I retry unmounting it first?"))) == ResponseType.YES) {
try {
Gocrypt.unmount_vault (vault.mount_point);
Gocrypt.mount_vault (vault.path, vault.mount_point, password, (vault.mode == "r"), vault.reverse);
vault.is_mounted = true;
sync_treeview_from_conf ();
} catch (Error e) {
Utils.show_error (this, "%s\n%s".printf (_("Error re-mounting vault:"), e.message));
Expand All @@ -262,7 +267,6 @@ namespace Cryptor.UI {
} else {
try {
Gocrypt.unmount_vault (vault.mount_point);
vault.is_mounted = false;
sync_treeview_from_conf ();
} catch (Error e) {
Utils.show_error (this, "%s\n%s".printf (_("Error unmounting vault:"), e.message));
Expand All @@ -278,19 +282,20 @@ namespace Cryptor.UI {
var menu = new Gtk.Menu ();
menu.reserve_toggle_size = false;
var open = Utils.get_image_menu_item ("gtk-open", _("Open directory"));
open.sensitive = vault.is_mounted;
var mounted = vault.is_mounted ();
open.sensitive = mounted;
open.activate.connect (() => {
Utils.open_folder (vault.mount_point);
});
var mount = Utils.get_image_menu_item (vault.is_mounted ? "gtk-cancel" : "gtk-apply", vault.is_mounted ? _("Unmount") : _("Mount"));
var mount = Utils.get_image_menu_item (mounted ? "gtk-cancel" : "gtk-apply", mounted ? _("Unmount") : _("Mount"));
mount.activate.connect (on_mount_clicked);
var edit = Utils.get_image_menu_item ("gtk-edit", _("Edit"));
edit.sensitive = !vault.is_mounted;
edit.sensitive = !mounted;
edit.activate.connect (() => {
show_vault_window (get_selected_rownumber ());
});
var remove = Utils.get_image_menu_item ("gtk-remove", _("Remove"));
remove.sensitive = !vault.is_mounted;
remove.sensitive = !mounted;
remove.activate.connect (() => {
config.vaults.remove (vault);
sync_treeview_from_conf ();
Expand Down Expand Up @@ -353,7 +358,7 @@ namespace Cryptor.UI {
list_store.set_value (iter, 2, v.path);
list_store.set_value (iter, 3, v.mount_point);
list_store.set_value (iter, 4, mode);
list_store.set_value (iter, 5, v.is_mounted);
list_store.set_value (iter, 5, v.is_mounted ());
}
}

Expand All @@ -364,7 +369,7 @@ namespace Cryptor.UI {
}
if (config.umount_on_quit) {
foreach (var vault in config.vaults) {
if (vault.is_mounted) {
if (vault.is_mounted ()) {
try {
Gocrypt.unmount_vault (vault.mount_point);
} catch (Error e) {
Expand Down
Loading