aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-12-31 20:19:51 +0100
committerfiaxh <git@mx.ax.lt>2017-12-31 22:48:14 +0100
commitc7c1fb51246f52801de118e1f519630a51adefdb (patch)
tree5ccc394ba6c525d24b586a63cc52cf5a348ab926
parent119e7cce4ffb2774fa77bbfcef5dda80a5483f3f (diff)
downloaddino-c7c1fb51246f52801de118e1f519630a51adefdb.tar.gz
dino-c7c1fb51246f52801de118e1f519630a51adefdb.zip
Restore window state (size, maximized, position)
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.md2
-rw-r--r--cmake/FindVala.cmake2
-rw-r--r--libdino/src/entity/settings.vala61
-rw-r--r--main/src/ui/unified_window.vala31
-rw-r--r--plugins/http-files/src/file_provider.vala46
6 files changed, 118 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a1097125..ec6583a1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,7 +121,7 @@ if(NOT VALA_EXECUTABLE)
unset(VALA_EXECUTABLE CACHE)
endif()
-find_package(Vala 0.30 REQUIRED)
+find_package(Vala 0.34 REQUIRED)
if(VALA_VERSION VERSION_GREATER "0.34.90" AND VALA_VERSION VERSION_LESS "0.36.1")
# Due to a bug on 0.36.0 (and pre-releases), we need to disable FAST_VAPI
set(DISABLE_FAST_VAPI yes)
diff --git a/README.md b/README.md
index e98be6e8..717cff34 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ Build
* C compiler
* gettext
* ninja(-build) (recommend)
-* valac (≥ 0.30)
+* valac (≥ 0.34)
**Run-time dependencies**
diff --git a/cmake/FindVala.cmake b/cmake/FindVala.cmake
index f9ed7636..91bfe86d 100644
--- a/cmake/FindVala.cmake
+++ b/cmake/FindVala.cmake
@@ -47,7 +47,7 @@
# Search for the valac executable in the usual system paths
# Some distributions rename the valac to contain the major.minor in the binary name
find_package(GObject REQUIRED)
-find_program(VALA_EXECUTABLE NAMES valac valac-0.36 valac-0.34 valac-0.32 valac-0.30)
+find_program(VALA_EXECUTABLE NAMES valac valac-0.38 valac-0.36 valac-0.34 valac-0.32)
mark_as_advanced(VALA_EXECUTABLE)
# Determine the valac version
diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala
index bf1ebed4..f94a92ca 100644
--- a/libdino/src/entity/settings.vala
+++ b/libdino/src/entity/settings.vala
@@ -11,6 +11,12 @@ public class Settings : Object {
send_marker_ = col_to_bool_or_default("send_marker", true);
notifications_ = col_to_bool_or_default("notifications", true);
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
+
+ current_width = col_to_int_or_default("window_width", 1200);
+ current_height = col_to_int_or_default("window_height", 700);
+ is_maximized = col_to_bool_or_default("window_maximized", false);
+ position_x = col_to_int_or_default("window_position_x", -1);
+ position_y = col_to_int_or_default("window_position_y", -1);
}
private bool col_to_bool_or_default(string key, bool def) {
@@ -18,6 +24,11 @@ public class Settings : Object {
return val != null ? bool.parse(val) : def;
}
+ private int col_to_int_or_default(string key, int def) {
+ string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
+ return val != null ? int.parse(val) : def;
+ }
+
private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
@@ -53,6 +64,56 @@ public class Settings : Object {
convert_utf8_smileys_ = value;
}
}
+
+ private int current_width_;
+ public int current_width {
+ get { return current_width_; }
+ set {
+ if (value == current_width_) return;
+ db.settings.insert().or("REPLACE").value(db.settings.key, "window_width").value(db.settings.value, value.to_string()).perform();
+ current_width_ = value;
+ }
+ }
+
+ private int current_height_;
+ public int current_height {
+ get { return current_height_; }
+ set {
+ if (value == current_height_) return;
+ db.settings.insert().or("REPLACE").value(db.settings.key, "window_height").value(db.settings.value, value.to_string()).perform();
+ current_height_ = value;
+ }
+ }
+
+ private bool is_maximized_;
+ public bool is_maximized {
+ get { return is_maximized_; }
+ set {
+ if (value == is_maximized_) return;
+ db.settings.insert().or("REPLACE").value(db.settings.key, "window_maximized").value(db.settings.value, value.to_string()).perform();
+ is_maximized_ = value;
+ }
+ }
+
+ private int position_x_;
+ public int position_x {
+ get { return position_x_; }
+ set {
+ if (value == position_x_) return;
+ db.settings.insert().or("REPLACE").value(db.settings.key, "window_position_x").value(db.settings.value, value.to_string()).perform();
+ position_x_ = value;
+ }
+ }
+
+ private int position_y_;
+ public int position_y {
+ get { return position_y_; }
+ set {
+ if (value == position_y_) return;
+ db.settings.insert().or("REPLACE").value(db.settings.key, "window_position_y").value(db.settings.value, value.to_string()).perform();
+ position_y_ = value;
+ }
+ }
}
}
diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala
index 15218e17..8bcb2c57 100644
--- a/main/src/ui/unified_window.vala
+++ b/main/src/ui/unified_window.vala
@@ -21,10 +21,15 @@ public class UnifiedWindow : Window {
private StreamInteractor stream_interactor;
private Conversation? conversation;
+ private Application app;
public UnifiedWindow(Application application, StreamInteractor stream_interactor) {
- Object(application : application, default_width : 1200, default_height : 700);
+ Object(application : application);
this.stream_interactor = stream_interactor;
+ this.app = application;
+
+ restore_window_size();
+
this.get_style_context().add_class("dino-main");
setup_headerbar();
@@ -120,6 +125,30 @@ public class UnifiedWindow : Window {
}
}
+ private void restore_window_size() {
+ default_width = app.settings.current_width;
+ default_height = app.settings.current_height;
+ if (app.settings.is_maximized) this.maximize();
+ if (app.settings.position_x != -1 && app.settings.position_y != -1) {
+ move(app.settings.position_x, app.settings.position_y);
+ }
+
+ delete_event.connect(() => {
+ int x, y;
+ get_position(out x, out y);
+ app.settings.position_x = x;
+ app.settings.position_y = y;
+
+ int width, height;
+ get_size(out width, out height);
+ app.settings.current_width = width;
+ app.settings.current_height = height;
+
+ app.settings.is_maximized = is_maximized;
+ return false;
+ });
+ }
+
private bool on_focus_in_event() {
stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation);
urgency_hint = false;
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 21d833eb..9a9db072 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -62,28 +62,30 @@ public class FileProvider : Dino.FileProvider, Object {
});
if (content_length != null && int.parse(content_length) < 5000000) {
FileTransfer file_transfer = new FileTransfer();
- Soup.Request request = session.request(message.body);
- request.send_async.begin(null, (obj, res) => {
- try {
- file_transfer.input_stream = request.send_async.end(res);
- } catch (Error e) {
- return;
- }
- file_transfer.account = conversation.account;
- file_transfer.counterpart = message.counterpart;
- file_transfer.ourpart = message.ourpart;
- file_transfer.encryption = Encryption.NONE;
- file_transfer.time = message.time;
- file_transfer.local_time = message.local_time;
- file_transfer.direction = message.direction;
- file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
- file_transfer.mime_type = content_type;
- file_transfer.size = int.parse(content_length);
- file_transfer.state = FileTransfer.State.NOT_STARTED;
- file_transfer.provider = 0;
- file_transfer.info = message.body;
- file_incoming(file_transfer);
- });
+ try {
+ Soup.Request request = session.request(message.body);
+ request.send_async.begin(null, (obj, res) => {
+ try {
+ file_transfer.input_stream = request.send_async.end(res);
+ } catch (Error e) {
+ return;
+ }
+ file_transfer.account = conversation.account;
+ file_transfer.counterpart = message.counterpart;
+ file_transfer.ourpart = message.ourpart;
+ file_transfer.encryption = Encryption.NONE;
+ file_transfer.time = message.time;
+ file_transfer.local_time = message.local_time;
+ file_transfer.direction = message.direction;
+ file_transfer.file_name = message.body.substring(message.body.last_index_of("/") + 1);
+ file_transfer.mime_type = content_type;
+ file_transfer.size = int.parse(content_length);
+ file_transfer.state = FileTransfer.State.NOT_STARTED;
+ file_transfer.provider = 0;
+ file_transfer.info = message.body;
+ file_incoming(file_transfer);
+ });
+ } catch (Error e) { }
}
});
}