Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a newsrc autosave timer.

If newsrc is dirty utomatically save newsrc files after x minutes
have elapsed. Set to 0 in preferences dialog to disable.
  • Loading branch information...
commit 1547322ff266144abe08837280605f1f96da6706 1 parent 9383aac
@lostcoder authored
View
4 pan/data-impl/data-impl.cc
@@ -56,7 +56,9 @@ DataImpl :: DataImpl (bool unit_test, int cache_megs, DataIO * io):
_cache (get_cache_path(), cache_megs),
_unit_test (unit_test),
_data_io (io),
- _descriptions_loaded (false)
+ _descriptions_loaded (false),
+ newsrc_autosave_id (0),
+ newsrc_autosave_timeout (0)
{
rebuild_backend ();
}
View
13 pan/data-impl/data-impl.h
@@ -614,6 +614,19 @@ namespace pan
public:
const ArticleFilter _article_filter;
+
+ private:
+ guint newsrc_autosave_id;
+ guint newsrc_autosave_timeout;
+ public:
+ bool in_newsrc_cb;
+ void set_newsrc_autosave_timeout(guint seconds)
+ {newsrc_autosave_timeout = seconds;}
+ void save_newsrc_files()
+ {
+ save_newsrc_files(*_data_io);
+ newsrc_autosave_id = 0;
+ }
};
}
View
3  pan/data-impl/groups.cc
@@ -208,6 +208,9 @@ DataImpl :: load_newsrc_files (const DataIO& data_io)
void
DataImpl :: save_newsrc_files (DataIO& data_io) const
{
+ if (!in_newsrc_cb && newsrc_autosave_id)
+ g_source_remove( newsrc_autosave_id );
+
if (_unit_test)
return;
View
14 pan/data-impl/headers.cc
@@ -838,6 +838,17 @@ DataImpl :: save_headers (DataIO& data_io, const Quark& group) const
/*******
********
*******/
+namespace
+{
+ gboolean nrc_as_cb(gpointer ptr)
+ {
+ DataImpl *data = static_cast<DataImpl*>(ptr);
+ data->in_newsrc_cb = true;
+ data->save_newsrc_files();
+ data->in_newsrc_cb = false;
+ return FALSE;
+ }
+}
void
DataImpl :: mark_read (const Article & a, bool read)
@@ -876,6 +887,9 @@ DataImpl :: mark_read (const Article ** articles,
fire_group_counts (group, g._unread_count, g._article_count);
on_articles_changed (group, it->second, false);
}
+
+ if( !newsrc_autosave_id && newsrc_autosave_timeout )
+ newsrc_autosave_id = g_timeout_add_seconds( newsrc_autosave_timeout * 60, nrc_as_cb, this);
}
View
1  pan/gui/pan.cc
@@ -317,6 +317,7 @@ main (int argc, char *argv[])
std::cerr << _("Please configure Pan's news servers before using it as an nzb client.") << std::endl;
return 0;
}
+ data.set_newsrc_autosave_timeout( prefs.get_int("newsrc-autosave-timeout-min", 10 ));
// instantiate the queue...
WorkerPool worker_pool (4, true);
View
21 pan/gui/prefs-ui.cc
@@ -89,6 +89,22 @@ namespace
return r;
}
+ void spin_value_changed_cb( GtkSpinButton *spin, gpointer data)
+ {
+ const char * key = (const char*) g_object_get_data (G_OBJECT(spin), PREFS_KEY);
+ Prefs *prefs = static_cast<Prefs*>(data);
+ prefs->set_int(key, gtk_spin_button_get_value_as_int(spin));
+ }
+ GtkWidget* new_spin_button (const char *key, int low, int high, Prefs &prefs)
+ {
+ guint tm = prefs.get_int(key, 5 );
+ GtkAdjustment *adj = (GtkAdjustment*) gtk_adjustment_new(tm, low, high, 1.0, 1.0, 1.0);
+ GtkWidget *w = gtk_spin_button_new( adj, 1.0, 0);
+ g_object_set_data_full(G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free);
+ g_signal_connect (w, "value_changed", G_CALLBACK(spin_value_changed_cb), &prefs);
+ return w;
+ }
+
GtkWidget* new_orient_radio (GtkWidget* prev, const char* label, const char* value, std::string& cur, Prefs& prefs)
{
GtkWidget * r = prev==0
@@ -449,13 +465,16 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
HIG :: workarea_add_wide_control (t, &row, w);
HIG::workarea_add_section_divider (t, &row);
HIG :: workarea_add_section_title (t, &row, _("Articles"));
- HIG :: workarea_add_section_spacer (t, row, 3);
+ HIG :: workarea_add_section_spacer (t, row, 4);
w = new_check_button (_("Space selects next article rather than next unread"), "space-selects-next-article", true, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
w = new_check_button (_("Smooth scrolling"), "smooth-scrolling", true, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
w = new_check_button (_("Clear article cache on shutdown"), "clear-article-cache-on-shutdown", false, prefs);
HIG :: workarea_add_wide_control (t, &row, w);
+ w = new_spin_button ("newsrc-autosave-timeout-min", 0, 60, prefs);
+ l = gtk_label_new(_("Minutes to autosave newsrc files."));
+ HIG::workarea_add_row (t, &row, l, w);
HIG :: workarea_finish (t, &row);
gtk_notebook_append_page (GTK_NOTEBOOK(notebook), t, gtk_label_new_with_mnemonic(_("_Behavior")));
Please sign in to comment.
Something went wrong with that request. Please try again.