[med-svn] [aghermann] 09/23: move common code for hypnogram im/export from menu callbacks to hypnogram.cc
andrei zavada
hmmr-guest at alioth.debian.org
Sat Aug 17 18:05:41 UTC 2013
This is an automated email from the git hooks/post-receive script.
hmmr-guest pushed a commit to branch master
in repository aghermann.
commit ae0732e7c6273b776171136efc8c26eeba669ce0
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Sun Aug 4 02:03:36 2013 +0300
move common code for hypnogram im/export from menu callbacks to hypnogram.cc
---
src/aghermann/ui/sf/hypnogram.cc | 84 ++++++++++++++++++++++++++++++++++-
src/aghermann/ui/sf/hypnogram_cb.cc | 57 ++----------------------
src/aghermann/ui/sf/mainmenu_cb.cc | 11 +++--
src/aghermann/ui/sf/sf.hh | 4 +-
4 files changed, 97 insertions(+), 59 deletions(-)
diff --git a/src/aghermann/ui/sf/hypnogram.cc b/src/aghermann/ui/sf/hypnogram.cc
index d9a8fec..7ff9b6b 100644
--- a/src/aghermann/ui/sf/hypnogram.cc
+++ b/src/aghermann/ui/sf/hypnogram.cc
@@ -10,7 +10,7 @@
*/
-
+#include <fstream>
#include <cairo/cairo.h>
@@ -119,6 +119,88 @@ draw_hypnogram( cairo_t *cr)
+
+
+
+
+void
+aghui::SScoringFacility::
+do_dialog_import_hypnogram()
+{
+ GtkWidget *f_chooser =
+ gtk_file_chooser_dialog_new(
+ "Import Scores",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ if ( gtk_dialog_run( (GtkDialog*)f_chooser) == GTK_RESPONSE_ACCEPT ) {
+ gchar *fname = gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser);
+ // count lines first
+ ifstream f (fname);
+ string t;
+ size_t c = 0;
+ while ( not getline(f, t).eof() )
+ ++c;
+ size_t our_pages = sepisode().sources.front().pages();
+ if ( c != our_pages && // allow for last page scored but discarded in CHypnogram as incomplete
+ c != our_pages+1 )
+ pop_ok_message(
+ wSF,
+ "Page count in current hypnogram (%zu,"
+ " even allowing for one incomplete extra) is not equal"
+ " to the number of lines in <i>%s</i> (%zu).\n\n"
+ "Please trim the file contents and try again.",
+ fname, c, our_pages);
+ else {
+ for ( auto &F : sepisode().sources )
+ F.load_canonical( fname, _p.ext_score_codes);
+ get_hypnogram();
+ calculate_scored_percent();
+ queue_redraw_all();
+ }
+ }
+ gtk_widget_destroy( f_chooser);
+}
+
+
+void
+aghui::SScoringFacility::
+do_dialog_export_hypnogram() const
+{
+ GtkWidget *f_chooser =
+ gtk_file_chooser_dialog_new(
+ "Export Scores",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ if ( gtk_dialog_run( (GtkDialog*)f_chooser) == GTK_RESPONSE_ACCEPT ) {
+ gchar *fname = gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser);
+ // put_hypnogram(); // side-effect being, implicit flash of SScoringFacility::sepisode.sources // do this elsewhere
+ sepisode().sources.front().save_canonical( fname);
+ }
+ gtk_widget_destroy( f_chooser);
+}
+
+
+
+void
+aghui::SScoringFacility::
+do_clear_hypnogram()
+{
+ hypnogram.assign(
+ hypnogram.size(),
+ sigfile::SPage::score_code( sigfile::SPage::TScore::none));
+ put_hypnogram(); // side-effect being, implicit flash of SScoringFacility::sepisode.sources
+ calculate_scored_percent();
+ queue_redraw_all();
+}
+
+
+
// Local Variables:
// Mode: c++
// indent-tabs-mode: 8
diff --git a/src/aghermann/ui/sf/hypnogram_cb.cc b/src/aghermann/ui/sf/hypnogram_cb.cc
index 8f93f8a..0c108e8 100644
--- a/src/aghermann/ui/sf/hypnogram_cb.cc
+++ b/src/aghermann/ui/sf/hypnogram_cb.cc
@@ -9,8 +9,6 @@
* License: GPL
*/
-#include <fstream>
-
#include "aghermann/rk1968/rk1968.hh"
#include "aghermann/ui/globals.hh"
#include "sf.hh"
@@ -124,41 +122,7 @@ iSFScoreImport_activate_cb(
{
auto& SF = *(SScoringFacility*)userdata;
- GtkWidget *f_chooser =
- gtk_file_chooser_dialog_new(
- "Import Scores",
- NULL,
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- if ( gtk_dialog_run( (GtkDialog*)f_chooser) == GTK_RESPONSE_ACCEPT ) {
- gchar *fname = gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser);
- // count lines first
- ifstream f (fname);
- string t;
- size_t c = 0;
- while ( not getline(f, t).eof() )
- ++c;
- size_t our_pages = SF.sepisode().sources.front().pages();
- if ( c != our_pages && // allow for last page scored but discarded in CHypnogram as incomplete
- c != our_pages+1 )
- pop_ok_message(
- SF.wSF,
- "Page count in current hypnogram (%zu,"
- " even allowing for one incomplete extra) is not equal"
- " to the number of lines in <i>%s</i> (%zu).\n\n"
- "Please trim the file contents and try again.",
- fname, c, our_pages);
- else {
- for ( auto &F : SF.sepisode().sources )
- F.load_canonical( fname, SF._p.ext_score_codes);
- SF.get_hypnogram();
- SF.calculate_scored_percent();
- SF.queue_redraw_all();
- }
- }
- gtk_widget_destroy( f_chooser);
+ SF.do_dialog_import_hypnogram();
}
void
@@ -168,18 +132,7 @@ iSFScoreExport_activate_cb(
{
auto& SF = *(SScoringFacility*)userdata;
- GtkWidget *f_chooser = gtk_file_chooser_dialog_new( "Export Scores",
- NULL,
- GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- if ( gtk_dialog_run( (GtkDialog*)f_chooser) == GTK_RESPONSE_ACCEPT ) {
- gchar *fname = gtk_file_chooser_get_filename( (GtkFileChooser*)f_chooser);
- SF.put_hypnogram(); // side-effect being, implicit flash of SScoringFacility::sepisode.sources
- SF.sepisode().sources.front().save_canonical( fname);
- }
- gtk_widget_destroy( f_chooser);
+ SF.do_dialog_export_hypnogram();
}
@@ -191,11 +144,7 @@ iSFScoreClear_activate_cb(
{
auto& SF = *(SScoringFacility*)userdata;
- SF.hypnogram.assign( SF.hypnogram.size(),
- sigfile::SPage::score_code( sigfile::SPage::TScore::none));
- SF.put_hypnogram(); // side-effect being, implicit flash of SScoringFacility::sepisode.sources
- SF.calculate_scored_percent();
- SF.queue_redraw_all();
+ SF.do_clear_hypnogram();
}
} // extern "C"
diff --git a/src/aghermann/ui/sf/mainmenu_cb.cc b/src/aghermann/ui/sf/mainmenu_cb.cc
index e2118ae..8e6e82b 100644
--- a/src/aghermann/ui/sf/mainmenu_cb.cc
+++ b/src/aghermann/ui/sf/mainmenu_cb.cc
@@ -185,7 +185,8 @@ iSFMontageScoreImport_activate_cb(
gpointer userdata)
{
auto& SF = *(SScoringFacility*)userdata;
-
+
+ SF.do_dialog_import_hypnogram();
}
void
@@ -194,7 +195,8 @@ iSFMontageScoreExport_activate_cb(
const gpointer userdata)
{
const auto& SF = *(SScoringFacility*)userdata;
-
+
+ SF.do_dialog_export_hypnogram();
}
void
@@ -203,11 +205,14 @@ iSFMontageScoreClear_activate_cb(
gpointer userdata)
{
auto& SF = *(SScoringFacility*)userdata;
-
+
+ SF.do_clear_hypnogram();
}
+
+
void
iSFMontageClose_activate_cb(
const GtkMenuItem*,
diff --git a/src/aghermann/ui/sf/sf.hh b/src/aghermann/ui/sf/sf.hh
index ff528d1..ad259a0 100644
--- a/src/aghermann/ui/sf/sf.hh
+++ b/src/aghermann/ui/sf/sf.hh
@@ -497,8 +497,10 @@ class SScoringFacility
// main montage menu
public:
void update_main_menu_items();
+ void do_dialog_import_hypnogram();
+ void do_dialog_export_hypnogram() const;
+ void do_clear_hypnogram();
- public:
void do_score_forward( char score_ch);
void do_score_back( char score_ch);
--
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git
More information about the debian-med-commit
mailing list