[PATCH] Use gtk_tree_model_get_value() to get the index and date of a dive

Miika Turkia miika.turkia at gmail.com
Tue Sep 18 21:30:11 PDT 2012


I still have one of the weird ones left.
$ ./subsurface dives/*
- sort by date, newest dive first (if not so by default)
- select four topmost dives
- right click and select Create new trip above
- 3 of the selected dives form the new trip, one is left behind

And continuing with creation of one more new group with the existing
selection resulted only one dive to be moved to the new group.

Options what one can do seem to depend on which dive you right click.
Clicking on the first one in selection does not allow for creating new
group. Selecting the second from top, moves only one dive to new
group.. selecting the last moves all but one.

miika

On Wed, Sep 19, 2012 at 6:55 AM, Miika Turkia <miika.turkia at gmail.com> wrote:
> On Wed, Sep 19, 2012 at 1:44 AM, Lubomir I. Ivanov <neolit123 at gmail.com> wrote:
>> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>>
>> When retrieving the index and date from the model and iterator
>> in divelist.c:date_data_func(), use gtk_tree_model_get_value()
>> to write to Gvalue entries, which should be technically safer
>> than the varargs list of gtk_tree_model_get(), but shouldn't break either.
>>
>> This seems to solve a bug on Ubuntu 12.0.4, where the DIVE_INDEX in the
>> abovementioned functon is never set to -1 (entry is a Trip).
>
> Bingo! This seems to fix the issue. You have really nailed a couple bad ones!
>
> BTW the UI freeze you mention later on the thread with gdb...switch to
> text console and kill gdb. (You could probably get something out of
> gdb if you run it in screen and check stuff out on the text console
> before kiling). Of course the crash got already solved, but if this
> hits again in the future.
>
> miika
>
>> The same bug cannot be reporoduced on Debian 6.0.4 and Windows 7
>> with the latest GTK / GLib.
>>
>> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
>> ---
>>  dive.h     |  5 +++++
>>  divelist.c | 16 ++++++++++++----
>>  2 files changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/dive.h b/dive.h
>> index 5637edf..5ff883a 100644
>> --- a/dive.h
>> +++ b/dive.h
>> @@ -8,6 +8,11 @@
>>  #include <glib/gstdio.h>
>>  #include <libxml/tree.h>
>>
>> +/* Since glib-2.30 */
>> +#ifndef G_VALUE_INIT
>> +       #define G_VALUE_INIT  { 0, { { 0 } } }
>> +#endif
>> +
>>  /*
>>   * Some silly typedefs to make our units very explicit.
>>   *
>> diff --git a/divelist.c b/divelist.c
>> index aedcdf0..8df006a 100644
>> --- a/divelist.c
>> +++ b/divelist.c
>> @@ -375,18 +375,23 @@ static void date_data_func(GtkTreeViewColumn *col,
>>                            GtkTreeIter *iter,
>>                            gpointer data)
>>  {
>> -       int val, idx, nr;
>> +       int nr;
>>         struct tm *tm;
>>         time_t when;
>>         char buffer[40];
>>
>> -       gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &val, -1);
>> +       GValue gv_idx = G_VALUE_INIT;
>> +       GValue gv_date = G_VALUE_INIT;
>> +
>> +       gtk_tree_model_get_value(model, iter, DIVE_INDEX, &gv_idx);
>> +       gtk_tree_model_get_value(model, iter, DIVE_DATE, &gv_date);
>> +
>>         nr = gtk_tree_model_iter_n_children(model, iter);
>>         /* 2038 problem */
>> -       when = val;
>> +       when = g_value_get_long(&gv_date);
>>
>>         tm = gmtime(&when);
>> -       if (idx < 0) {
>> +       if (g_value_get_int(&gv_idx) < 0) {
>>                 snprintf(buffer, sizeof(buffer),
>>                         "Trip %s, %s %d, %d (%d dive%s)",
>>                         weekday(tm->tm_wday),
>> @@ -401,6 +406,9 @@ static void date_data_func(GtkTreeViewColumn *col,
>>                         tm->tm_mday, tm->tm_year + 1900,
>>                         tm->tm_hour, tm->tm_min);
>>         }
>> +
>> +       g_value_unset(&gv_idx);
>> +       g_value_unset(&gv_date);
>>         g_object_set(renderer, "text", buffer, NULL);
>>  }
>>
>> --
>> 1.7.11.msysgit.0
>>
>> _______________________________________________
>> subsurface mailing list
>> subsurface at hohndel.org
>> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface


More information about the subsurface mailing list