Skip to content

Commit

Permalink
#38: Starting again activity does does not use category of past activity
Browse files Browse the repository at this point in the history
This was possibly a problem with hamster legacy. In the gk+2 world,
starting a fact with an empty category via dbus would autmatically
append the most recent cateogory of the fact. Now with gtk+3,
an empty category is passed through verbatim.

Thankfully, filtering the GetActivities method from the entry text
returns the categories in recent order and we can pick the last used.
  • Loading branch information
aquaherd committed Mar 7, 2021
1 parent 003535a commit 68da2e6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion panel-plugin/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ places_button_get_ellipsize(PlacesButton *self)
{
g_assert(PLACES_IS_BUTTON(self));

DBG("returning %s", self->ellipsize);
DBG("returning %d", self->ellipsize);
return self->ellipsize;
}

Expand Down
14 changes: 7 additions & 7 deletions panel-plugin/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

typedef struct _fact
{
gint id; // 0
int id; // 0
time_t startTime; // 1
time_t endTime; // 2
gchar *description; // 3
gchar *name; // 4
gint activityId; // 5
gchar *category; // 6
gchar **tags; // 7
char *description; // 3
char *name; // 4
int activityId; // 5
char *category; // 6
char **tags; // 7
time_t date; // 8
gint seconds; // 9
int seconds; // 9
}fact;

fact*
Expand Down
66 changes: 51 additions & 15 deletions panel-plugin/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum
BTNEDIT,
BTNCONT,
ID,
CATEGORY,
NUM_COL
};

Expand Down Expand Up @@ -182,14 +183,14 @@ hview_cb_match_select(GtkEntryCompletion *widget,
GtkTreeIter *iter,
HamsterView *view)
{
gchar *activity, *category;
gchar fact[256];
gint id = 0;
char *activity, *category;
char fact[256];
int id = 0;

gtk_tree_model_get(model, iter, 0, &activity, 1, &category, -1);
snprintf(fact, sizeof(fact), "%s@%s", activity, category);
hamster_call_add_fact_sync(view->hamster, fact, 0, 0, FALSE, &id, NULL, NULL);
DBG("activated: %s[%d]", fact, id);
DBG("selected: %s[%d]", fact, id);
if(!view->donthide)
hview_popup_hide(view);
g_free(activity);
Expand All @@ -201,8 +202,33 @@ static void
hview_cb_entry_activate(GtkEntry *entry,
HamsterView *view)
{
const gchar *fact = gtk_entry_get_text(GTK_ENTRY(view->entry));
gint id = 0;
const char *fact = gtk_entry_get_text(GTK_ENTRY(view->entry));
int id = 0;
char buffer[256];
GVariant* res;
GVariant* child;
char* act = NULL;
char* cat = NULL;

if (!strchr(fact, '@'))
{
hamster_call_get_activities_sync(view->hamster, fact, &res, 0, 0);
if (NULL != res && g_variant_n_children(res) > 0)
{
child = g_variant_get_child_value(res, 0); // topmost in history is OK
if (child)
{
g_variant_get(child, "(ss)", &act, &cat);
if (NULL != act && NULL != cat)
{
snprintf(buffer, sizeof(buffer), "%s@%s", act, cat);
fact = buffer;
}
g_variant_unref(child);
}
}
}

hamster_call_add_fact_sync(view->hamster, fact, 0, 0, FALSE, &id, NULL, NULL);
DBG("activated: %s[%d]", fact, id);
if(!view->donthide)
Expand Down Expand Up @@ -252,24 +278,32 @@ hview_cb_tv_button_press(GtkWidget *tv,
GtkTreeIter iter;
if (gtk_tree_selection_get_selected(selection, &model, &iter))
{
gint id;
gchar *icon;
gchar *fact;
gtk_tree_model_get(model, &iter, ID, &id, BTNCONT, &icon, TITLE, &fact, -1);
//DBG("%s:%d:%s", column->title, id, icon);
int id;
char* icon;
char* fact;
char* category;
gtk_tree_model_get(model, &iter,
ID, &id,
BTNCONT, &icon,
TITLE, &fact,
CATEGORY, &category, -1);
DBG("%s:%s:%s", fact, category, icon);
if(!strcmp(gtk_tree_view_column_get_title (column), "ed"))
{
GVariant *dummy = g_variant_new_int32(id);
GVariant *var = g_variant_new_variant(dummy);
window_server_call_edit_sync(view->windowserver, var, NULL, NULL);
window_server_call_edit_sync(view->windowserver, var, NULL, NULL);
}
else if(!strcmp(gtk_tree_view_column_get_title(column), "ct") && !strcmp(icon, "gtk-media-play"))
{
DBG("Resume %s", fact);
hamster_call_add_fact_sync(view->hamster, fact, 0, 0, FALSE, &id, NULL, NULL);
char fact_at_category[255];
snprintf(fact_at_category, sizeof(fact_at_category), "%s@%s", fact, category);
DBG("Resume %s", fact_at_category);
hamster_call_add_fact_sync(view->hamster, fact_at_category, 0, 0, FALSE, &id, NULL, NULL);
}
g_free(icon);
g_free(fact);
g_free(category);
}
gtk_tree_path_free(path);
}
Expand Down Expand Up @@ -670,6 +704,7 @@ hview_store_update(HamsterView *view, fact *activity, GHashTable *categories)
BTNEDIT, "gtk-edit",
BTNCONT, hview_activity_stopped(activity) ? "gtk-media-play" : "",
ID, activity->id,
CATEGORY, activity->category,
-1);

hview_increment_category_time(activity->category, activity->seconds, categories);
Expand Down Expand Up @@ -729,6 +764,7 @@ hview_completion_update(HamsterView *view)
0, actlow, 1, cat, -1);
g_free(actlow);
}
g_variant_unref(res);
}
}
}
Expand Down Expand Up @@ -903,7 +939,7 @@ hamster_view_init(XfcePanelPlugin* plugin)
/* storage */
view->storeActivities = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
view->storeFacts = gtk_list_store_new(NUM_COL, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
view->summary = gtk_label_new(NULL);
view->treeview = gtk_tree_view_new();

Expand Down

0 comments on commit 68da2e6

Please sign in to comment.