[med-svn] [SCM] aghermann branch, master, updated. 4b06a66467a52311d413e817136ece62c0e9c24a

Andrei Zavada johnhommer at gmail.com
Sun Jul 21 19:56:37 UTC 2013


The following commit has been merged in the master branch:
commit b180ff18ca5b5667ef68d57ee9ece79421ec6d6e
Author: Andrei Zavada <johnhommer at gmail.com>
Date:   Sat Jul 20 22:39:32 2013 +0300

    use some rich text in Scan Report log

diff --git a/src/aghermann/expdesign/primaries.cc b/src/aghermann/expdesign/primaries.cc
index 13692fb..720f91d 100644
--- a/src/aghermann/expdesign/primaries.cc
+++ b/src/aghermann/expdesign/primaries.cc
@@ -145,19 +145,34 @@ log_message( const char* fmt, ...)
 	va_list ap;
 	va_start (ap, fmt);
 
-	char *buf;
-	assert (vasprintf( &buf, fmt, ap) > 0);
+	char *buf0;
+	int np = vasprintf( &buf0, fmt, ap);
+	char *buf = buf0;
+	if ( np > 0 ) {
+		TLogEntryStyle style =
+			(strncmp( buf, "$$", 2) == 0)
+			? ((buf += 2), TLogEntryStyle::bold)
+			: (strncmp( buf, "//", 2) == 0)
+			? ((buf += 2), TLogEntryStyle::italic)
+			: TLogEntryStyle::plain;
+		fprintf( stdout, "%s\n", buf0);
+		_error_log.emplace_back( buf, style);
+	}
+	if ( np != -1 )
+		free( (void*)buf0);
 
-	_error_log += buf;
-	if ( strlen(buf) && *(buf + strlen(buf)-1) != '\n' ) {
-		_error_log += "\n";
-		fprintf( stdout, "%s\n", buf);
-	} else
-		fputs( buf, stdout);
+	va_end (ap);
+}
 
-	free( (void*)buf);
 
-	va_end (ap);
+string
+agh::CExpDesign::
+error_log_serialize() const
+{
+	string ret;
+	for ( const auto& E : _error_log )
+		ret += E.first + '\n';
+	return ret;
 }
 
 
diff --git a/src/aghermann/expdesign/primaries.hh b/src/aghermann/expdesign/primaries.hh
index cafe74f..80fbf6c 100644
--- a/src/aghermann/expdesign/primaries.hh
+++ b/src/aghermann/expdesign/primaries.hh
@@ -310,18 +310,18 @@ class CExpDesign {
 			return _session_dir.substr( _session_dir.rfind( '/'));
 		}
 
+      // error log
+	enum class TLogEntryStyle { plain, bold, italic };
+	const list<pair<string, TLogEntryStyle>>&
+	error_log() const
+		{ return _error_log; }
 	void reset_error_log()
-		{
-			_error_log.clear();
-		}
+		{ _error_log.clear(); }
 	const char* last_error() const
-		{
-			return &_error_log[_error_log.rfind("\n", _error_log.size()-1)];
-		}
-	const string& error_log() const
-		{
-			return _error_log;
-		}
+		{ return _error_log.back().first.c_str(); }
+	string error_log_serialize() const;
+	size_t error_log_n_messages() const
+		{ return _error_log.size(); }
 	void log_message( const char* fmt, ...);
 
       // contains
@@ -483,7 +483,8 @@ class CExpDesign {
 
 	int	_status;
 	string	_session_dir;
-	string	_error_log;
+	list<pair<string, TLogEntryStyle>>
+		_error_log;
 
 	sid_t	_id_pool;
       // load/save
diff --git a/src/aghermann/expdesign/tree-scanner.cc b/src/aghermann/expdesign/tree-scanner.cc
index d581371..30e4f62 100644
--- a/src/aghermann/expdesign/tree-scanner.cc
+++ b/src/aghermann/expdesign/tree-scanner.cc
@@ -159,14 +159,14 @@ register_intree_source( sigfile::CTypedSource&& F,
 
 		// refuse to register sources of wrong subjects
 		if ( j_name != F().subject().id ) {
-			log_message( "%s: file belongs to subject %s (\"%s\"), is misplaced here under subject \"%s\"\n",
+			log_message( "%s: file belongs to subject %s (\"%s\"), is misplaced here under subject \"%s\"",
 				     F().filename(), F().subject().id.c_str(), F().subject().name.c_str(), j_name.c_str());
 			return -1;
 		}
 		try {
 			auto existing_group = group_of( F().subject().id.c_str());
 			if ( g_name != existing_group ) {
-				log_message( "%s: subject %s (\"%s\") belongs to a different group (\"%s\")\n",
+				log_message( "%s: subject %s (\"%s\") belongs to a different group (\"%s\")",
 					     F().filename(), F().subject().id.c_str(), F().subject().name.c_str(), existing_group);
 				return -1;
 			}
@@ -176,12 +176,12 @@ register_intree_source( sigfile::CTypedSource&& F,
 
 		// but correct session/episode fields
 		if ( d_name != F().session() ) {
-			log_message( "%s: correcting embedded session \"%s\" to match placement in the tree (\"%s\")\n",
+			log_message( "%s: correcting embedded session \"%s\" to match placement in the tree (\"%s\")",
 				     F().filename(), F().session(), d_name.c_str());
 			F().set_session( d_name.c_str());
 		}
 		if ( e_name != F().episode() ) {
-			log_message( "%s: correcting embedded episode \"%s\" to match file name\n",
+			log_message( "%s: correcting embedded episode \"%s\" to match file name",
 				     F().filename(), F().episode());
 			F().set_episode( e_name.c_str());
 		}
@@ -213,11 +213,11 @@ register_intree_source( sigfile::CTypedSource&& F,
 		switch ( J->measurements[F().session()].add_one(
 				 move(F), fft_params, swu_params, mc_params) ) {  // this will do it
 		case AGH_EPSEQADD_OVERLAP:
-			log_message( "%s: not added as it overlaps with existing episodes\n",
+			log_message( "%s: not added as it overlaps with existing episodes",
 				     F().filename());
 			return -1;
 		case AGH_EPSEQADD_TOOFAR:
-			log_message( "%s: not added as it is too far removed from the rest\n",
+			log_message( "%s: not added as it is too far removed from the rest",
 				     F().filename());
 			return -1;
 		default:
@@ -225,12 +225,12 @@ register_intree_source( sigfile::CTypedSource&& F,
 		}
 
 	} catch (invalid_argument ex) {
-		log_message( ex.what() + '\n');
+		log_message( ex.what());
 		if ( reason_if_failed_p )
 			*reason_if_failed_p = ex.what();
 		return -1;
 	} catch (int status) {
-		log_message( "Bad edf header or data\n");
+		log_message( "Bad edf header or data");
 		if ( reason_if_failed_p )
 			*reason_if_failed_p = "Bad edf header or data";
 		return -1;
@@ -286,13 +286,15 @@ edf_file_processor( const char *fname, const struct stat*, int flag, struct FTW
 				using namespace sigfile;
 				CTypedSource F {fname, (size_t)roundf(__expdesign->fft_params.pagesize)};
 				string st = F().explain_status();
-				if ( not st.empty() )
-					__expdesign->log_message( "In %s:\n%s\n", fname, st.c_str());
+				if ( not st.empty() ) {
+					__expdesign->log_message( "$$%s:", fname);
+					__expdesign->log_message( "%s", st.c_str());
+				}
 				// we only support edf and edfplus/edf_c
 				if ( agh::CExpDesign::is_supported_source(F) )
 					__expdesign -> register_intree_source( move(F));
 				else
-					__expdesign -> log_message( "File %s: unsupported format\n", fname);
+					__expdesign -> log_message( "File %s: unsupported format", fname);
 
 			} catch ( invalid_argument ex) {
 				__expdesign->log_message(ex.what());
@@ -359,7 +361,7 @@ scan_tree( TMsmtCollectProgressIndicatorFun user_progress_fun)
 			for ( auto &D : J.measurements )
 				if ( D.second.episodes.size() < n_episodes &&
 				     complete_episode_set.front() != D.second.episodes.begin()->name() ) { // the baseline is missing
-					log_message( "No Baseline episode in %s's %s: skip this session\n",
+					log_message( "No Baseline episode in %s's %s: skip this session",
 						     J.id.c_str(), D.first.c_str());
 					J.measurements.erase(D.first);
 					goto startover;
diff --git a/src/aghermann/model/achermann.cc b/src/aghermann/model/achermann.cc
index 03eb09f..c33a40e 100644
--- a/src/aghermann/model/achermann.cc
+++ b/src/aghermann/model/achermann.cc
@@ -105,7 +105,7 @@ setup_modrun( const string& j, const string& d, const string& h,
 		fprintf( stderr, "CExpDesign::setup_modrun( %s, %s, %s): %s\n", j.c_str(), d.c_str(), h.c_str(), ex.what());
 		return -1;
 	} catch (int ex) { // thrown by CModelRun ctor
-		log_message( "CExpDesign::setup_modrun( %s, %s, %s): %s\n", j.c_str(), d.c_str(), h.c_str(), CProfile::explain_status(ex).c_str());
+		log_message( "CExpDesign::setup_modrun( %s, %s, %s): %s", j.c_str(), d.c_str(), h.c_str(), CProfile::explain_status(ex).c_str());
 		return ex;
 	}
 
diff --git a/src/aghermann/ui/mw/construct.cc b/src/aghermann/ui/mw/construct.cc
index 12ac6f5..b084975 100644
--- a/src/aghermann/ui/mw/construct.cc
+++ b/src/aghermann/ui/mw/construct.cc
@@ -315,6 +315,17 @@ SExpDesignUIWidgets ()
 		throw runtime_error ("Failed to construct widgets");
 
 	gtk_widget_override_font( (GtkWidget*)tScanLog, font_desc);
+	gtk_text_buffer_create_tag(
+		gtk_text_view_get_buffer( tScanLog),
+		"bold",
+		"weight", PANGO_WEIGHT_BOLD,
+		NULL);
+	gtk_text_buffer_create_tag(
+		gtk_text_view_get_buffer( tScanLog),
+		"italic",
+		"style", PANGO_STYLE_ITALIC,
+		NULL);
+
 	// free? unref? leak some?
 
       // ****************** settings
diff --git a/src/aghermann/ui/mw/populate.cc b/src/aghermann/ui/mw/populate.cc
index 3fdffd7..d4af478 100644
--- a/src/aghermann/ui/mw/populate.cc
+++ b/src/aghermann/ui/mw/populate.cc
@@ -127,10 +127,41 @@ populate( bool do_load)
 		set_controls_for_empty_experiment( false);
 	}
 
-	if ( not ED->error_log().empty() ) {
+	if ( ED->error_log_n_messages() > 0 ) {
 		if ( not suppress_scan_report ) {
-			gtk_text_buffer_set_text( gtk_text_view_get_buffer( tScanLog),
-						  ED->error_log().c_str(), -1);
+			auto buffer = gtk_text_view_get_buffer( tScanLog);
+			for ( const auto& L : ED->error_log() ) {
+
+				GtkTextIter X0, X9;
+				gtk_text_buffer_get_end_iter(
+					buffer, &X0);
+				gint x0 = gtk_text_iter_get_offset( &X0);
+
+				gtk_text_buffer_insert_at_cursor(
+					buffer, (L.first + '\n').c_str(), -1);
+				gtk_text_buffer_get_iter_at_offset(
+					buffer, &X0, x0);
+				gtk_text_buffer_get_end_iter(
+					buffer, &X9);
+				// gtk_text_iter_backward_cursor_position(
+				// 	&X9);
+
+				switch ( L.second ) {
+				case agh::CExpDesign::TLogEntryStyle::bold:
+					gtk_text_buffer_apply_tag_by_name(
+						buffer, "bold",
+						&X0, &X9);
+					break;
+				case agh::CExpDesign::TLogEntryStyle::italic:
+					gtk_text_buffer_apply_tag_by_name(
+						buffer, "italic",
+						&X0, &X9);
+					break;
+				case agh::CExpDesign::TLogEntryStyle::plain:
+				default:
+					break;
+				}
+			}
 			gtk_widget_show_all( (GtkWidget*)wScanLog);
 		} else
 			gdk_window_beep( gtk_widget_get_window( (GtkWidget*)wMainWindow));

-- 
Sleep experiment manager



More information about the debian-med-commit mailing list