[pan2/testing: 75/279] todo: tooltip for gtkliststore
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 75/279] todo: tooltip for gtkliststore
- Date: Sat, 3 Dec 2011 22:29:40 +0000 (UTC)
commit 82ba763226683b43e79f1477e336120ca87f03f3
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date: Wed Jun 1 13:22:34 2011 +0200
todo: tooltip for gtkliststore
pan/general/log.cc | 12 +++++++
pan/general/log.h | 15 ++++++++
pan/gui/log-ui.cc | 81 ++++++++++++++++++++++++++++++++++++++++++---
pan/gui/log-ui.h | 4 ++
pan/gui/post-ui.cc | 1 -
pan/tasks/task-upload.cc | 70 +++++++++++++++++++++++++++++++++++----
pan/tasks/task-upload.h | 3 ++
7 files changed, 172 insertions(+), 14 deletions(-)
---
diff --git a/pan/general/log.cc b/pan/general/log.cc
index 36079d1..e4b9fec 100644
--- a/pan/general/log.cc
+++ b/pan/general/log.cc
@@ -61,6 +61,18 @@ Log :: fire_cleared () {
***/
void
+Log :: add_entry(Entry& e, std::deque<Entry>& list)
+{
+ _entries.resize (_entries.size() + 1);
+ Entry& tmp (_entries.back());
+ tmp.date = e.date;
+ tmp.severity = e.severity;
+ tmp.message = e.message;
+ tmp.list = list;
+ fire_entry_added (tmp);
+}
+
+void
Log :: add (Severity severity, const char * msg)
{
_entries.resize (_entries.size() + 1);
diff --git a/pan/general/log.h b/pan/general/log.h
index 99dab9e..1ba04fe 100644
--- a/pan/general/log.h
+++ b/pan/general/log.h
@@ -48,6 +48,9 @@ namespace pan
time_t date;
Severity severity;
std::string message;
+ std::deque<Entry> list;
+ Entry() {}
+ Entry(std::deque<Entry>& d) : list(d) {}
};
/** Interface class for objects that listen to a Log's events */
@@ -64,6 +67,15 @@ namespace pan
void add (Severity, const char *);
void add_va (Severity, const char *, ...);
const entries_t& get_entries () const { return _entries; }
+ void append_entries(entries_t& entries)
+ {
+ for (entries_t::iterator it = entries.begin(); it != entries.end(); ++it)
+ {
+ _entries.resize(entries.size()+1);
+ _entries.push_back(*it);
+ }
+ }
+ void add_entry(Entry& e, std::deque<Entry>& list);
void clear ();
void add_listener (Listener* l) { _listeners.insert(l); }
void remove_listener (Listener* l) { _listeners.erase(l); }
@@ -85,6 +97,9 @@ namespace pan
static void add_err_va (const char *, ...);
static void add_urgent (const char * s) { Log::get().add ((Severity)(PAN_SEVERITY_ERROR|PAN_SEVERITY_URGENT), s); }
static void add_urgent_va (const char *, ...);
+ static void entry_added (const Entry& e) { Log::get().fire_entry_added(e); }
+
+ static void add_entry_list(Entry& e, std::deque<Entry>& list) { Log::get().add_entry (e, list); }
};
}
diff --git a/pan/gui/log-ui.cc b/pan/gui/log-ui.cc
index 05a4d72..219094f 100644
--- a/pan/gui/log-ui.cc
+++ b/pan/gui/log-ui.cc
@@ -20,6 +20,7 @@
#include <config.h>
#include <ostream>
#include <fstream>
+#include <iostream>
extern "C" {
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -51,10 +52,10 @@ namespace
virtual void on_log_entry_added (const Log::Entry& e) {
GtkTreeIter iter;
gtk_list_store_prepend (myStore, &iter);
- gtk_list_store_set (myStore, &iter,
+ gtk_list_store_set (myStore, &iter,
COL_SEVERITY, (e.severity & Log::PAN_SEVERITY_ERROR),
COL_DATE, (unsigned long)e.date,
- COL_MESSAGE, e.message.c_str(), -1);
+ COL_MESSAGE, &e, -1);
}
virtual void on_log_cleared () {
@@ -110,22 +111,72 @@ namespace
namespace
{
+ std::string to_string(std::deque<Log::Entry> d)
+ {
+ std::string tmp;
+ foreach_const(std::deque<Log::Entry>, d, it)
+ tmp += it->message + "\n";
+ return tmp;
+ }
+}
+
+void
+pan :: do_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
+{
+ GtkWidget * w = treeview;
+ GtkTreeModel * model = gtk_tree_view_get_model(GTK_TREE_VIEW(w));
+ GtkTreeIter iter ;
+ GtkTreePath * path;
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(treeview),
+ (gint)event->x, (gint)event->y,
+ &path, NULL, NULL, NULL);
+ gtk_tree_model_get_iter(model,&iter,path);
+ Log::Entry* e;
+ gtk_tree_model_get (model, &iter, COL_MESSAGE, &e, -1);
+ if (!e->list.empty())
+ {
+
+ std::cerr<<"multi entry.\n";
+
+ GtkTextBuffer * tb;
+ std::string tmp (to_string(e->list));
+ int len = tmp.length();
+ gtk_text_buffer_set_text(tb, to_string(e->list).c_str(), len);
+ GtkWidget * w = gtk_text_view_new_with_buffer(tb);
+
+ gtk_widget_show_all(w);
+ }
+}
+
+gboolean
+pan :: on_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
+{
+ if (event->type == GDK_BUTTON_PRESS && event->button == 3)
+ {
+ do_popup_menu (treeview, event, userdata);
+ return true;
+ }
+ return false;
+}
+
+namespace
+{
GtkListStore*
create_model ()
{
GtkListStore * store = gtk_list_store_new (N_COLS,
G_TYPE_BOOLEAN, // true==error, false==info
G_TYPE_ULONG, // date
- G_TYPE_STRING); // message
+ G_TYPE_POINTER); // message
const Log::entries_t& entries (Log::get().get_entries());
foreach_const (Log::entries_t, entries, it) {
GtkTreeIter iter;
gtk_list_store_prepend (store, &iter);
- gtk_list_store_set (store, &iter,
+ gtk_list_store_set (store, &iter,
COL_SEVERITY, (it->severity & Log::PAN_SEVERITY_ERROR),
COL_DATE, (unsigned long)it->date,
- COL_MESSAGE, it->message.c_str(), -1);
+ COL_MESSAGE, &*it, -1);
}
return store;
@@ -161,6 +212,20 @@ namespace
s.resize (s.size()-1); // remove \n
g_object_set (renderer, "text", s.c_str(), NULL);
}
+
+ void
+ render_message (GtkTreeViewColumn * ,
+ GtkCellRenderer * renderer,
+ GtkTreeModel * model,
+ GtkTreeIter * iter,
+ gpointer )
+ {
+ Log::Entry* log_entry(0);
+ gtk_tree_model_get (model, iter, COL_MESSAGE, &log_entry, -1);
+ g_object_set (renderer, "text", log_entry ? log_entry->message.c_str() : "", NULL);
+ }
+
+
}
GtkWidget*
@@ -183,6 +248,7 @@ pan :: log_dialog_new (Prefs& prefs, GtkWindow* window)
GtkListStore * store = create_model ();
GtkWidget * view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
+
g_object_set_data_full (G_OBJECT(view), "listener", new MyLogListener(store), delete_my_log_listener);
GtkWidget * scroll = gtk_scrolled_window_new (0, 0);
gtk_container_set_border_width (GTK_CONTAINER(scroll), PAD_BIG);
@@ -217,7 +283,8 @@ pan :: log_dialog_new (Prefs& prefs, GtkWindow* window)
gtk_tree_view_column_set_sort_column_id (col, COL_MESSAGE);
gtk_tree_view_column_set_title (col, _("Message"));
gtk_tree_view_column_pack_start (col, text_renderer, true);
- gtk_tree_view_column_set_attributes (col, text_renderer, "text", COL_MESSAGE, NULL);
+ gtk_tree_view_column_set_cell_data_func (col, text_renderer, render_message, 0, 0);
+// gtk_tree_view_column_set_attributes (col, text_renderer, "text", COL_MESSAGE, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(view), col);
gtk_widget_show (view);
@@ -230,5 +297,7 @@ pan :: log_dialog_new (Prefs& prefs, GtkWindow* window)
if (window != 0)
gtk_window_set_transient_for (GTK_WINDOW(dialog), window);
+ g_signal_connect (view, "button-press-event", G_CALLBACK(on_button_pressed), view);
+
return dialog;
}
diff --git a/pan/gui/log-ui.h b/pan/gui/log-ui.h
index c337b25..ff59a89 100644
--- a/pan/gui/log-ui.h
+++ b/pan/gui/log-ui.h
@@ -28,6 +28,10 @@ namespace pan
* @ingroup GUI
*/
GtkWidget* log_dialog_new (Prefs& prefs, GtkWindow* parent);
+
+ gboolean on_button_pressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
+ void do_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata);
+
}
#endif
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 3ea8ec6..10f6f01 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -2301,7 +2301,6 @@ PostUI :: get_selected_files () const
return tasks;
}
-/// TODO debug!
void
PostUI :: remove_files (void)
{
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 6db5f48..1f871d5 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -174,6 +174,7 @@ TaskUpload :: update_work (NNTP* checkin_pending)
{
_state.set_completed();
set_finished(OK);
+
}
}
@@ -229,12 +230,38 @@ TaskUpload :: on_nntp_line (NNTP * nntp,
{}
+namespace
+{
+ void add_err_to_groups(std::deque<Log :: Entry> _logfile, const char* buf)
+ {
+ _logfile.resize(_logfile.size()+1);
+ Log :: Entry& e(_logfile.back());
+ e.severity = Log :: PAN_SEVERITY_ERROR;
+ e.date = time (NULL);
+ e.message = buf;
+ Log :: entry_added (e);
+ }
+
+ void add_info_to_groups(std::deque<Log :: Entry> _logfile, const char* buf)
+ {
+ _logfile.resize(_logfile.size()+1);
+ Log :: Entry& e(_logfile.back());
+ e.severity = Log :: PAN_SEVERITY_INFO;
+ e.date = time (NULL);
+ e.message = buf;
+ Log :: entry_added (e);
+ }
+}
+
void
TaskUpload :: on_nntp_done (NNTP * nntp,
Health health,
const StringView & response)
{
+ char buf[4096];
+ Log::Entry tmp;
+
needed_t::iterator it;
for (it=_needed.begin(); it!=_needed.end(); ++it)
if (it->second.nntp == nntp)
@@ -249,10 +276,9 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
increment_step(1);
break;
case ERR_NETWORK:
-// update_work();
-// check_in (nntp, health);
goto _end;
case ERR_COMMAND:
+ _severity_final = Log::PAN_SEVERITY_URGENT;
delete_cache(it->second);
_needed.erase (it);
break;
@@ -261,16 +287,46 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
switch (atoi(response.str))
{
case NO_POSTING:
- Log :: add_err(_("Posting failed: No Posts allowed by server."));
+ g_snprintf(buf,sizeof(buf), _("Posting of File %s (Part %d of %d) failed: No Posts allowed by server."),
+ _basename.c_str(), it->second.partno, _total_parts);
+ add_err_to_groups(_logfile, buf);
+ _severity_final = Log::PAN_SEVERITY_URGENT;
this->stop();
break;
case POSTING_FAILED:
- Log :: add_err_va (_("Posting failed: %s"), response.str);
+ g_snprintf(buf,sizeof(buf), _("Posting of File %s (Part %d of %d) failed: %s"),
+ _basename.c_str(), it->second.partno, _total_parts, response.str);
+ add_err_to_groups(_logfile, buf);
+ _severity_final = Log::PAN_SEVERITY_URGENT;
break;
case ARTICLE_POSTED_OK:
- if (_needed.empty() && post_ok)
- Log :: add_info_va(_("Posting of file %s succesful: %s"),
- _basename.c_str(), response.str);
+
+ std::cerr<<"OK!\n";
+
+ if (post_ok && !_needed.empty())
+ {
+ g_snprintf(buf,sizeof(buf), _("Posting of file %s (Part %d of %d) succesful: %s"),
+ _basename.c_str(), it->second.partno, _total_parts, response.str);
+ add_info_to_groups(_logfile, buf);
+ _severity_final = (Log :: Severity) (_severity_final | Log :: PAN_SEVERITY_INFO);
+ } else if (post_ok && _needed.empty())
+ {
+ g_snprintf(buf,sizeof(buf), _("Posting of file %s succesful: %s"),
+ _basename.c_str(), response.str);
+ _severity_final = (Log :: Severity) (_severity_final | Log :: PAN_SEVERITY_INFO);
+ tmp.message = buf;
+ tmp.date = time(NULL);
+ tmp.severity = _severity_final;
+ Log :: add_entry_list (tmp, _logfile);
+ } else
+ {
+ g_snprintf(buf,sizeof(buf), _("Posting of file %s not successful: Check the popup log!"),
+ _basename.c_str(), response.str);
+ tmp.message = buf;
+ tmp.date = time(NULL);
+ tmp.severity = _severity_final;
+ Log :: add_entry_list (tmp, _logfile);
+ }
break;
case TOO_MANY_CONNECTIONS:
// lockout for 120 secs, but try
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index 188f83d..f8093ea 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -29,6 +29,7 @@
#include <pan/data/article.h>
//#include <pan/data/article-cache.h>
#include <pan/data/data.h>
+#include <pan/general/log.h>
#include <pan/data/xref.h>
#include <pan/tasks/nntp.h>
#include <pan/tasks/task.h>
@@ -126,6 +127,8 @@ namespace pan
unsigned long _bytes;
Mutex mut;
// ArticleCache& _cache;
+ std::deque<Log::Entry> _logfile; // for intermediate updates
+ Log :: Severity _severity_final;
void build_needed_tasks(bool);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]