[pan2/testing: 207/279] - a few cleanups - added verbose flag
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 207/279] - a few cleanups - added verbose flag
- Date: Sat, 3 Dec 2011 22:38:58 +0000 (UTC)
commit dd54a741ff9e992a3e76a003f7a4a3a25b365260
Author: Heinrich Mueller <sphemuel stud informatik uni-erlangen de>
Date: Sat Sep 24 09:40:16 2011 +0200
- a few cleanups
- added verbose flag
pan/general/debug.cc | 1 +
pan/general/debug.h | 7 +++++++
pan/gui/gui.h | 2 +-
pan/gui/pan.cc | 26 ++++++++++++++------------
pan/gui/post-ui.cc | 7 ++-----
pan/gui/post-ui.h | 2 --
pan/tasks/task-article.cc | 18 ++++++++++++++++--
pan/tasks/task-post.cc | 8 +++++---
8 files changed, 46 insertions(+), 25 deletions(-)
---
diff --git a/pan/general/debug.cc b/pan/general/debug.cc
index d3b549f..d48ad4e 100644
--- a/pan/general/debug.cc
+++ b/pan/general/debug.cc
@@ -5,5 +5,6 @@ namespace pan
{
bool _debug_flag = false;
bool _debug_verbose_flag = false;
+ bool _verbose_flag = false;
}
diff --git a/pan/general/debug.h b/pan/general/debug.h
index ebaed84..2655f41 100644
--- a/pan/general/debug.h
+++ b/pan/general/debug.h
@@ -26,6 +26,7 @@ namespace pan
{
extern bool _debug_flag;
extern bool _debug_verbose_flag;
+ extern bool _verbose_flag;
}
@@ -43,6 +44,12 @@ namespace pan
std::cerr << LINE_ID << ' ' << A << '\n'; \
} while (0)
+#define verbose(A) \
+ do { \
+ if (_verbose_flag) \
+ std::cout << A << '\n'; \
+ } while (0)
+
#ifndef UNUSED
#ifdef __GNUC__
#define UNUSED __attribute__((unused))
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 5c74462..526da90 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -160,7 +160,7 @@ namespace pan
public:
static std::string prompt_user_for_save_path (GtkWindow * parent, const Prefs& prefs);
- static std::string prompt_user_for_filename (GtkWindow * parent, const Prefs& prefs);
+ static std::string prompt_user_for_filename (GtkWindow * parent, const Prefs& prefs);
private: // Queue::Listener
friend class Queue;
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index b5bf4d8..62b5c1e 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -34,7 +34,6 @@ extern "C" {
#include <pan/general/file-util.h>
#include <pan/general/worker-pool.h>
#include <pan/tasks/socket-impl-gio.h>
-//#include <pan/tasks/socket-impl-openssl.h>
#include <pan/tasks/task-groups.h>
#include <pan/tasks/task-xover.h>
#include <pan/tasks/nzb.h>
@@ -232,6 +231,7 @@ namespace
std::cerr << "Pan " << VERSION << "\n\n" <<
_("General Options\n"
" -h, --help Show this usage page.\n"
+" --verbose Be verbose (in non-GUI mode).\n"
"\n"
"URL Options\n"
" news:message-id Show the specified article.\n"
@@ -256,7 +256,7 @@ main (int argc, char *argv[])
g_thread_init (0);
g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);
- bool gui(true), nzb(false);
+ bool gui(true), nzb(false), verbosed(false);
std::string url;
std::string groups;
std::string nzb_output_path;
@@ -278,26 +278,31 @@ main (int argc, char *argv[])
else _debug_flag = true;
} else if (!strcmp (tok, "--nzb"))
nzb = true;
- else if (!strcmp (tok, "--version"))
- { std::cerr << "Pan " << VERSION << '\n'; return 0; }
+ else if (!strcmp (tok, "--version") || !strcmp (tok, "-v"))
+ { std::cerr << "Pan " << VERSION << '\n'; return EXIT_SUCCESS; }
else if (!strcmp (tok, "-o") && i<argc-1)
nzb_output_path = argv[++i];
else if (!memcmp (tok, "--output=", 9))
nzb_output_path = tok+9;
else if (!strcmp(tok,"-h") || !strcmp(tok,"--help"))
- { usage (); return 0; }
+ { usage (); return EXIT_SUCCESS; }
+ else if (!strcmp(tok, "--verbose") )
+ verbosed = true;
else {
nzb = true;
nzb_files.push_back (tok);
}
}
+ if (verbosed && !gui && nzb)
+ _verbose_flag = true;
+
if (gui)
gtk_init (&argc, &argv);
if (!gui && nzb_files.empty() && url.empty() && groups.empty()) {
std::cerr << _("Error: --no-gui used without nzb files or news:message-id.") << std::endl;
- return 0;
+ return EXIT_FAILURE;
}
Log::add_info_va (_("Pan %s started"), VERSION);
@@ -319,17 +324,14 @@ main (int argc, char *argv[])
if (nzb && data.get_servers().empty()) {
std::cerr << _("Please configure Pan's news servers before using it as an nzb client.") << std::endl;
- return 0;
+ return EXIT_FAILURE;
}
data.set_newsrc_autosave_timeout( prefs.get_int("newsrc-autosave-timeout-min", 10 ));
// instantiate the queue...
WorkerPool worker_pool (4, true);
- //////////////////////////
- /// DBG!!!!
GIOChannelSocket::Creator socket_creator;
- //////////////////////////
Queue queue (data, data, &socket_creator, worker_pool,
prefs.get_flag ("work-online", true),
@@ -349,7 +351,7 @@ main (int argc, char *argv[])
if (nzb_output_path.empty() && gui)
nzb_output_path = GUI::prompt_user_for_save_path (NULL, prefs);
if (nzb_output_path.empty()) // user pressed `cancel' when prompted
- return 0;
+ return EXIT_FAILURE;
// load the nzb files...
std::vector<Task*> tasks;
@@ -406,5 +408,5 @@ main (int argc, char *argv[])
g_mime_shutdown ();
Quark::dump (std::cerr);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index ed86f12..dd03a99 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -65,7 +65,7 @@ using namespace pan;
#define USER_AGENT_EXTRA_PREFS_KEY "user-agent-extra-info"
/** generates a unique message-id for a usenet post, consisting of
- * the current date and time (in seconds resolution) and three random numbers + part count
+ * the current time (in usec resolution) and three random numbers + part count
*/
void
PostUI :: generate_unique_id (StringView& mid, int cnt, std::string& s)
@@ -76,8 +76,6 @@ PostUI :: generate_unique_id (StringView& mid, int cnt, std::string& s)
struct timeval tv;
const time_t now (time(NULL));
struct tm local_now = *gmtime (&now);
- char buf[64];
- std::strftime (buf, sizeof(buf), "%Y%m%d%H%M%S", &local_now);
out << "pan$";
gettimeofday (&tv, NULL);
out << std::hex << tv.tv_usec << "$" << std::hex
@@ -87,14 +85,13 @@ PostUI :: generate_unique_id (StringView& mid, int cnt, std::string& s)
out<< '@';
// add domain
out << (mid.empty() ? "nospam.com" : mid);
-// std::cerr << "rng : "<<out.str()<<std::endl;
s = out.str();
}
namespace
{
#ifndef HAVE_CLOSE
-inline int close(int fd) {return _close(fd);}
+ inline int close(int fd) {return _close(fd);}
#endif
bool remember_charsets (true);
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index 887e9b7..0549ade 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -49,8 +49,6 @@ namespace pan
public:
typedef std::vector<Task*> tasks_t;
- typedef std::vector<TaskUpload*> bulk_tasks_t;
- typedef std::vector<TaskMultiPost*> inline_tasks_t;
static PostUI* create_window (GtkWindow*, Data&, Queue&, GroupServer&, Profiles&,
GMimeMessage*, Prefs&, GroupPrefs&, EncodeCache&);
diff --git a/pan/tasks/task-article.cc b/pan/tasks/task-article.cc
index 9d1a0e0..161f069 100644
--- a/pan/tasks/task-article.cc
+++ b/pan/tasks/task-article.cc
@@ -134,10 +134,15 @@ TaskArticle :: TaskArticle (const ServerRank & server_rank,
// initialize our progress status...
init_steps (all_bytes);
set_step (all_bytes - need_bytes);
+ const char *artsub(article.subject.c_str());
if (save_path.empty())
- set_status (article.subject.c_str());
+ set_status (artsub);
else
- set_status_va (_("Saving %s"), article.subject.c_str());
+ set_status_va (_("Saving %s"), artsub);
+
+ char buf[2048];
+ g_snprintf(buf,sizeof(buf), _("Saving %s"), artsub);
+ verbose (buf);
update_work ();
}
@@ -351,11 +356,20 @@ TaskArticle :: on_worker_done (bool cancelled)
// now that we're back in the main thread.
foreach_const(Decoder::log_t, _decoder->log_severe, it)
+ {
Log :: add_err(it->c_str());
+ verbose (it->c_str());
+ }
foreach_const(Decoder::log_t, _decoder->log_errors, it)
+ {
Log :: add_err(it->c_str());
+ verbose (it->c_str());
+ }
foreach_const(Decoder::log_t, _decoder->log_infos, it)
+ {
Log :: add_info(it->c_str());
+ verbose (it->c_str());
+ }
if (_decoder->mark_read)
_read.mark_read(_article);
diff --git a/pan/tasks/task-post.cc b/pan/tasks/task-post.cc
index 5af7d92..70ebec0 100644
--- a/pan/tasks/task-post.cc
+++ b/pan/tasks/task-post.cc
@@ -33,7 +33,7 @@ namespace
{
char buf[1024];
snprintf (buf, sizeof(buf), _("Posting \"%s\""), g_mime_message_get_subject(message));
- return std::string (buf);
+ return buf;
}
}
@@ -69,15 +69,17 @@ TaskPost :: on_nntp_done (NNTP * nntp,
{
_state.set_health (health);
+ const char* res(g_mime_message_get_subject(_message));
+
if (health == ERR_NETWORK)
{
Log :: add_err_va (_("Posting of \"%s\" failed: %s"),
- g_mime_message_get_subject(_message), response.str);
+ res, response.str);
_state.set_need_nntp (_server);
}
else {
Log :: add_info_va (_("Posting of \"%s\" succesful: %s"),
- g_mime_message_get_subject(_message), response.str);
+ res, response.str);
_state.set_completed ();
set_error (response);
set_finished (health);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]