[pan2/testing: 119/279] implementing autosave for drafts...
- From: Heinrich MÃller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2/testing: 119/279] implementing autosave for drafts...
- Date: Sat, 3 Dec 2011 22:32:11 +0000 (UTC)
commit d9006bb169f3487bd2f4f6dedaf983383887837c
Author: Heinrich Mueller <sphemuel stud informatik uni-erlangen de>
Date: Mon Jun 27 20:21:58 2011 +0200
implementing autosave for drafts...
pan/gui/post-ui.cc | 43 ++++++++++++++++++++++++++++++++++++-------
pan/gui/post-ui.h | 1 +
2 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 4bcf9dc..8b55064 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -1223,6 +1223,27 @@ PostUI :: open_draft ()
gtk_widget_destroy (d);
}
+void
+PostUI :: import_draft (const char* fn)
+{
+ std::cerr<<fn<<std::endl;
+
+ std::string txt;
+ if (file :: get_text_file_contents (fn, txt))
+ {
+ GMimeStream * stream = g_mime_stream_mem_new_with_buffer (txt.c_str(), txt.size());
+ GMimeParser * parser = g_mime_parser_new_with_stream (stream);
+ GMimeMessage * message = g_mime_parser_construct_message (parser);
+ if (message) {
+ set_message (message);
+ g_object_unref (G_OBJECT(message));
+ }
+ g_object_unref (G_OBJECT(parser));
+ g_object_unref (G_OBJECT(stream));
+ }
+ std::cerr<<txt<<std::endl;
+}
+
namespace
{
bool ua_extra=false;
@@ -2018,11 +2039,11 @@ PostUI :: group_entry_changed_cb (GtkEditable*, gpointer ui_gpointer)
gboolean
PostUI :: body_changed_idle (gpointer ui_gpointer)
{
- std::cerr<<"body changed idle\n";
PostUI * ui (static_cast<PostUI*>(ui_gpointer));
+ std::cerr<<"body changed idle "<<ui->_draft_autosave_timeout <<"\n";
ui->_body_changed_idle_tag = 0;
- ui->_draft_autosave_id = g_timeout_add_seconds( ui->_draft_autosave_timeout * 60, draft_save_cb, ui);
+ ui->_draft_autosave_id = g_timeout_add_seconds( ui->_draft_autosave_timeout, draft_save_cb, ui);
return false;
}
@@ -2662,16 +2683,14 @@ PostUI :: update_parts_tab()
gboolean
PostUI::draft_save_cb(gpointer ptr)
{
-
- std::cerr<<"auto-saving draft\n";
-
PostUI *data = static_cast<PostUI*>(ptr);
// data->in_newsrc_cb = true;
GMimeMessage * msg = data->new_message_from_ui (DRAFTING);
std::string& draft_filename (get_draft_filename ());
- const char* filename = draft_filename.c_str();
+ char * filename = g_build_filename (draft_filename.c_str(), "autosave", NULL);
+
+ std::cerr<<"auto-saving draft "<<filename<<"\n";
- errno = 0;
std::ofstream o (filename);
char * pch = g_mime_object_to_string ((GMimeObject *) msg);
o << pch;
@@ -2679,6 +2698,7 @@ PostUI::draft_save_cb(gpointer ptr)
g_free (pch);
g_object_unref (msg);
+ g_free(filename);
// data->in_newsrc_cb = false;
data->_unchanged_body = data->get_body ();
@@ -2731,6 +2751,15 @@ PostUI :: PostUI (GtkWindow * parent,
set_draft_autosave_timeout( prefs.get_int("draft-autosave-timeout-min", 10 ));
_draft_autosave_id = g_timeout_add_seconds( _draft_autosave_timeout * 60, draft_save_cb, this);
+ /* import old draft from autosave file */
+ struct stat sb;
+ char *buf = g_build_filename(get_draft_filename().c_str(), "autosave", NULL);
+ stat (buf, &sb);
+ std::cerr<<"importing file "<<buf<<" "<<sb.st_size<<" "<<stat (buf, &sb)<<std::endl;
+ if (stat (buf, &sb)==0)
+ import_draft(buf);
+ g_free(buf);
+
g_assert (profiles.has_profiles());
g_return_if_fail (message != 0);
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index 5da4abe..2a60b86 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -73,6 +73,7 @@ namespace pan
void apply_profile ();
void save_draft ();
void open_draft ();
+ void import_draft (const char* fn);
void prompt_for_charset ();
void send_now ();
void send_and_save_now ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]