-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VENOM-302: Refactor UserInfoWidget to mvvm
- Loading branch information
Showing
5 changed files
with
146 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* UserInfoWidget.vala | ||
* | ||
* Copyright (C) 2013-2018 Venom authors and contributors | ||
* | ||
* This file is part of Venom. | ||
* | ||
* Venom is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Venom is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Venom. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Venom { | ||
[GtkTemplate(ui = "/im/tox/venom/ui/user_info_widget.ui")] | ||
public class UserInfoWidget : Gtk.Box { | ||
[GtkChild] private Gtk.Entry entry_username; | ||
[GtkChild] private Gtk.Entry entry_statusmessage; | ||
[GtkChild] private Gtk.Image image_userimage; | ||
[GtkChild] private Gtk.Label label_id; | ||
[GtkChild] private Gtk.FileChooserButton filechooser; | ||
[GtkChild] private Gtk.Button apply; | ||
|
||
private ILogger logger; | ||
private UserInfoViewModel view_model; | ||
|
||
private string _filename; | ||
public string filename { | ||
get { return _filename = filechooser.get_filename(); } | ||
set { filechooser.set_filename(value); } | ||
} | ||
|
||
public UserInfoWidget(ILogger logger, UserInfo user_info) { | ||
logger.d("UserInfoWidget created."); | ||
this.logger = logger; | ||
this.view_model = new UserInfoViewModel(logger, user_info); | ||
|
||
view_model.bind_property("username", entry_username, "text", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.BIDIRECTIONAL); | ||
view_model.bind_property("statusmessage", entry_statusmessage, "text", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.BIDIRECTIONAL); | ||
view_model.bind_property("userimage", image_userimage, "pixbuf", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.BIDIRECTIONAL); | ||
view_model.bind_property("tox-id", label_id, "label", GLib.BindingFlags.SYNC_CREATE); | ||
view_model.bind_property("filename", this, "filename", GLib.BindingFlags.SYNC_CREATE); | ||
|
||
filechooser.file_set.connect(view_model.on_file_selected); | ||
apply.clicked.connect(view_model.on_apply_clicked); | ||
} | ||
|
||
~UserInfoWidget() { | ||
logger.d("UserInfoWidget destroyed."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* UserInfoViewModel.vala | ||
* | ||
* Copyright (C) 2018 Venom authors and contributors | ||
* | ||
* This file is part of Venom. | ||
* | ||
* Venom is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Venom is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Venom. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace Venom { | ||
public class UserInfoViewModel : GLib.Object { | ||
public string username { get; set; } | ||
public string statusmessage { get; set; } | ||
public Gdk.Pixbuf userimage { get; set; } | ||
public string tox_id { get; set; } | ||
public Gdk.Pixbuf tox_qr_code { get; set; } | ||
public string filename { get; set; } | ||
|
||
private ILogger logger; | ||
private UserInfo user_info; | ||
|
||
public UserInfoViewModel(ILogger logger, UserInfo user_info) { | ||
logger.d("UserInfoViewModel created."); | ||
this.logger = logger; | ||
this.user_info = user_info; | ||
|
||
username = user_info.get_name(); | ||
statusmessage = user_info.get_status_message(); | ||
userimage = user_info.get_image(); | ||
tox_id = user_info.get_tox_id(); | ||
filename = ""; | ||
} | ||
|
||
public void on_apply_clicked() { | ||
logger.d("on_apply_clicked."); | ||
user_info.set_name(username); | ||
user_info.set_status_message(statusmessage); | ||
user_info.set_image(userimage); | ||
user_info.info_changed(this); | ||
} | ||
|
||
public void on_file_selected() { | ||
logger.d("on_file_selected."); | ||
try { | ||
userimage = new Gdk.Pixbuf.from_file_at_scale(filename, 100, 100, true); | ||
} catch (Error e) { | ||
logger.e("Could not read file: " + e.message); | ||
} | ||
} | ||
|
||
~UserInfoViewModel() { | ||
logger.d("UserInfoViewModel destroyed."); | ||
} | ||
} | ||
} |