Commit 75bd12cc authored by guinux's avatar guinux

in-app notifications

parent 5e5f1fc3
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -61,30 +61,39 @@ namespace Pamac {
if (manager_window == null) {
return 1;
}
if (cmd.get_arguments ()[0] == "pamac-updater") {
if (!started) {
manager_window.update_lists ();
manager_window.present ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
if (!started) {
manager_window.update_lists.begin (() => {
started = true;
}
if (cmd.get_arguments ()[0] == "pamac-updater") {
manager_window.display_package_queue.clear ();
manager_window.main_stack.visible_child_name = "browse";
manager_window.filters_stack.visible_child_name = "updates";
} else if (cmd.get_arguments ().length == 3
&& cmd.get_arguments ()[1] == "--search") {
manager_window.display_package_queue.clear ();
manager_window.search_button.active = true;
var entry = manager_window.search_comboboxtext.get_child () as Gtk.Entry;
entry.set_text (cmd.get_arguments ()[2]);
} else {
manager_window.refresh_packages_list ();
}
});
} else if (cmd.get_arguments ()[0] == "pamac-updater") {
manager_window.display_package_queue.clear ();
manager_window.main_stack.visible_child_name = "browse";
manager_window.filters_stack.visible_child_name = "updates";
} else if (!started) {
manager_window.update_lists ();
} else if (cmd.get_arguments ().length == 3
&& cmd.get_arguments ()[1] == "--search") {
manager_window.display_package_queue.clear ();
manager_window.search_button.active = true;
var entry = manager_window.search_comboboxtext.get_child () as Gtk.Entry;
entry.set_text (cmd.get_arguments ()[2]);
} else {
manager_window.refresh_packages_list ();
started = true;
}
if (cmd.get_arguments ().length == 3) {
if (cmd.get_arguments ()[1] == "--search") {
manager_window.display_package_queue.clear ();
manager_window.search_button.active = true;
var entry = manager_window.search_comboboxtext.get_child () as Gtk.Entry;
entry.set_text (cmd.get_arguments ()[2]);
}
}
manager_window.present ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
return 0;
}
......
......@@ -51,6 +51,10 @@ namespace Pamac {
[GtkChild]
Gtk.HeaderBar headerbar;
[GtkChild]
Gtk.Revealer notification_revealer;
[GtkChild]
Gtk.Label notification_label;
[GtkChild]
public Gtk.Stack main_stack;
[GtkChild]
Gtk.Button button_back;
......@@ -197,6 +201,7 @@ namespace Pamac {
List<Package> repos_updates;
List<AURPackage> aur_updates;
uint notification_timeout_id;
uint search_entry_timeout_id;
string search_string;
Gtk.Label pending_label;
......@@ -432,6 +437,9 @@ namespace Pamac {
stderr.printf ("SpawnError: %s\n", e.message);
}
}
// connect notification signal
transaction.emit_notification.connect ((msg) => { show_in_app_notification (msg, true); });
}
[GtkCallback]
......@@ -445,6 +453,41 @@ namespace Pamac {
}
}
public void show_in_app_notification (string msg, bool expires) {
close_in_app_notification ();
notification_label.label = msg;
notification_revealer.reveal_child = true;
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
if (expires) {
notification_timeout_id = Timeout.add (5000, () => {
notification_revealer.reveal_child = false;
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
notification_timeout_id = 0;
return false;
});
}
}
public void close_in_app_notification () {
if (notification_timeout_id != 0) {
Source.remove (notification_timeout_id);
notification_timeout_id = 0;
}
notification_revealer.reveal_child = false;
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
}
[GtkCallback]
void on_notification_close_button_clicked () {
close_in_app_notification ();
}
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur) {
support_aur (enable_aur);
......@@ -599,7 +642,18 @@ namespace Pamac {
pending_label.sensitive = active;
}
public void update_lists () {
public async void update_lists () {
// loading notification
show_in_app_notification (dgettext (null, "Loading") + "...", false);
Timeout.add (200, () => {
update_lists_real ();
Idle.add (update_lists.callback);
return false;
});
yield;
}
void update_lists_real () {
Gtk.Label label;
label = create_list_label (dgettext (null, "Categories"));
filters_listbox.add (label);
......@@ -698,6 +752,9 @@ namespace Pamac {
build_files_row.add (label);
properties_listbox.add (build_files_row);
properties_listbox.select_row (properties_listbox.get_row_at_index (0));
// close loading notification
close_in_app_notification ();
}
void clear_lists () {
......
......@@ -290,6 +290,7 @@ namespace Pamac {
return index;
}
}
stdout.printf ("\n");
}
bool ask_user (string question) {
......
......@@ -37,6 +37,8 @@ namespace Pamac {
bool summary_shown;
bool commit_transaction_answer;
public signal void emit_notification (string message);
public TransactionGtk (Database database, Gtk.ApplicationWindow? application_window) {
Object (database: database, application_window: application_window);
}
......@@ -97,8 +99,6 @@ namespace Pamac {
start_building.connect (start_progressbar_pulse);
stop_building.connect (stop_progressbar_pulse);
write_pamac_config_finished.connect (set_trans_flags);
// notify
Notify.init (dgettext (null, "Package Manager"));
// flags
set_trans_flags ();
// ask_confirmation option
......@@ -721,31 +721,13 @@ namespace Pamac {
box.add (scrolledwindow);
dialog.default_width = 600;
dialog.default_height = 300;
Timeout.add (1000, () => {
try {
var notification = new Notify.Notification (dgettext (null, "Package Manager"),
message,
"system-software-update");
notification.show ();
} catch (Error e) {
stderr.printf ("Notify Error: %s", e.message);
}
return false;
});
dialog.run ();
dialog.destroy ();
}
void on_finished (bool success) {
if (success) {
try {
var notification = new Notify.Notification (dgettext (null, "Package Manager"),
dgettext (null, "Transaction successfully finished"),
"system-software-update");
notification.show ();
} catch (Error e) {
stderr.printf ("Notify Error: %s", e.message);
}
emit_notification (dgettext (null, "Transaction successfully finished"));
show_warnings (false);
} else {
warning_textbuffer = new StringBuilder ();
......
......@@ -216,7 +216,6 @@ namespace Pamac {
}
void on_get_authorization_finished (bool authorized) {
emit_script_output ("");
get_authorization_finished (authorized);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment