-
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 logic from ui classes
* Refactor into viewmodel * Visualise errors in addcontactdialog
- Loading branch information
Showing
8 changed files
with
264 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 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
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
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,64 @@ | ||
/* | ||
* AddContactViewModel.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 AddContactViewModel : GLib.Object { | ||
public string contact_id { get; set; } | ||
public string contact_message { get; set; } | ||
public bool contact_id_error_visible { get; set; } | ||
public string contact_id_error_message { get; set; } | ||
|
||
private ILogger logger; | ||
private AddContactWidgetListener listener; | ||
|
||
public AddContactViewModel(ILogger logger, AddContactWidgetListener listener) { | ||
logger.d("AddContactViewModel created."); | ||
this.logger = logger; | ||
this.listener = listener; | ||
|
||
this.notify["contact-id"].connect(() => { contact_id_error_visible = false; }); | ||
} | ||
|
||
public void on_send() { | ||
try { | ||
listener.on_send_friend_request(contact_id, contact_message); | ||
} catch (Error e) { | ||
contact_id_error_message = "Could not add contact: " + e.message; | ||
contact_id_error_visible = true; | ||
logger.e(contact_id_error_message); | ||
return; | ||
} | ||
} | ||
|
||
public void on_paste_clipboard() { | ||
var clipboard = Gtk.Clipboard.@get(Gdk.SELECTION_CLIPBOARD); | ||
contact_id = clipboard.wait_for_text() ?? ""; | ||
} | ||
|
||
~AddContactViewModel() { | ||
logger.d("AddContactViewModel destroyed."); | ||
} | ||
} | ||
|
||
public interface AddContactWidgetListener : GLib.Object { | ||
public abstract void on_send_friend_request(string id, string message) throws Error; | ||
} | ||
} |
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,69 @@ | ||
/* | ||
* ContactListEntryViewModel.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 ContactListEntryViewModel : GLib.Object { | ||
private ILogger logger; | ||
private IContact contact; | ||
|
||
public string contact_name { get; set; } | ||
public string contact_status { get; set; } | ||
public Gdk.Pixbuf contact_image { get; set; } | ||
public string contact_status_image { get; set; } | ||
|
||
public ContactListEntryViewModel(ILogger logger, IContact contact) { | ||
logger.d("ContactListEntryViewModel created."); | ||
this.logger = logger; | ||
this.contact = contact; | ||
|
||
contact.changed.connect(update_contact); | ||
update_contact(); | ||
} | ||
|
||
public IContact get_contact() { | ||
return contact; | ||
} | ||
|
||
private void update_contact() { | ||
contact_name = contact.get_name_string(); | ||
contact_status = contact.get_status_string(); | ||
contact_image = contact.get_image(); | ||
contact_status_image = icon_name_from_status(contact.get_status()); | ||
} | ||
|
||
private string icon_name_from_status(UserStatus status) { | ||
switch (status) { | ||
case UserStatus.ONLINE: | ||
return R.icons.online; | ||
case UserStatus.AWAY: | ||
return R.icons.idle; | ||
case UserStatus.BUSY: | ||
return R.icons.busy; | ||
default: | ||
return R.icons.offline; | ||
} | ||
} | ||
|
||
~ContactListEntryViewModel() { | ||
logger.d("ContactListEntryViewModel destroyed."); | ||
} | ||
} | ||
} |
Oops, something went wrong.