From 837cfcae9d80210e70a131ef4e83c41a96a8cfbd Mon Sep 17 00:00:00 2001 From: Jason Uher Date: Wed, 20 Jun 2018 17:57:17 -0400 Subject: [PATCH] Add operational status to the list view Closes #132 --- src/gtk-sat-list.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- src/gtk-sat-list.h | 4 ++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/gtk-sat-list.c b/src/gtk-sat-list.c index 84705988..57508d7b 100644 --- a/src/gtk-sat-list.c +++ b/src/gtk-sat-list.c @@ -73,6 +73,7 @@ const gchar *SAT_LIST_COL_TITLE[SAT_LIST_COL_NUMBER] = { N_("Orbit"), N_("Vis"), N_("Decayed"), + N_("Status"), N_("BOLD") /* should never be seen */ }; @@ -105,6 +106,7 @@ const gchar *SAT_LIST_COL_HINT[SAT_LIST_COL_NUMBER] = { N_("Orbit Number"), N_("Visibility"), N_("Decayed"), + N_("Operational Status"), N_("---") }; @@ -134,6 +136,7 @@ const gfloat SAT_LIST_COL_XALIGN[SAT_LIST_COL_NUMBER] = { 0.0, // phase 1.0, // orbit 0.5, // visibility + 0.0, // Operational Status }; static void gtk_sat_list_class_init(GtkSatListClass * class); @@ -184,11 +187,20 @@ static void two_dec_cell_data_function(GtkTreeViewColumn * col, GtkTreeIter * iter, gpointer column); + +static void operational_status_cell_data_function(GtkTreeViewColumn * col, + GtkCellRenderer * renderer, + GtkTreeModel * model, + GtkTreeIter * iter, + gpointer column); + + static void event_cell_data_function(GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * model, GtkTreeIter * iter, gpointer column); + static gint event_cell_compare_function(GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data); @@ -440,6 +452,7 @@ static GtkTreeModel *create_and_fill_model(GHashTable * sats) G_TYPE_LONG, // orbit G_TYPE_STRING, // visibility G_TYPE_BOOLEAN, // decay + G_TYPE_INT, // Operational Status G_TYPE_INT // weight/bold ); @@ -485,8 +498,9 @@ static void sat_list_add_satellites(gpointer key, gpointer value, SAT_LIST_COL_DELAY, 0.0, SAT_LIST_COL_MA, sat->ma, SAT_LIST_COL_PHASE, sat->phase, - SAT_LIST_COL_ORBIT, sat->orbit, SAT_LIST_COL_DECAY, - !decayed(sat), -1); + SAT_LIST_COL_ORBIT, sat->orbit, + SAT_LIST_COL_STAT_OPERATIONAL, (char *) sat->tle.status, + SAT_LIST_COL_DECAY, !decayed(sat), -1); } /** Update satellites */ @@ -856,12 +870,69 @@ static void check_and_set_cell_renderer(GtkTreeViewColumn * column, event_cell_data_function, GUINT_TO_POINTER(i), NULL); break; + + case SAT_LIST_COL_STAT_OPERATIONAL: + gtk_tree_view_column_set_cell_data_func(column, + renderer, + operational_status_cell_data_function, + GUINT_TO_POINTER(i), NULL); + break; + default: break; } } +/* Render column containing the operational status */ +static void operational_status_cell_data_function(GtkTreeViewColumn * col, + GtkCellRenderer * renderer, + GtkTreeModel * model, + GtkTreeIter * iter, + gpointer column) +{ + gint number; + guint coli = GPOINTER_TO_UINT(column); + + (void)col; /* avoid unusued parameter compiler warning */ + + gtk_tree_model_get(model, iter, coli, &number, -1); + + switch (number) + { + + case OP_STAT_OPERATIONAL: + g_object_set(renderer, "text", "Operational", NULL); + break; + + case OP_STAT_NONOP: + g_object_set(renderer, "text", "Non-operational", NULL); + break; + + case OP_STAT_PARTIAL: + g_object_set(renderer, "text", "Partially operational", NULL); + break; + + case OP_STAT_STDBY: + g_object_set(renderer, "text", "Backup/Standby", NULL); + break; + + case OP_STAT_SPARE: + g_object_set(renderer, "text", "Spare", NULL); + break; + + case OP_STAT_EXTENDED: + g_object_set(renderer, "text", "Extended Mission", NULL); + break; + + default: + g_object_set(renderer, "text", "Unknown", NULL); + break; + + } + +} + /* Render column containg lat/lon by using this instead of the default data function, we can control the number of decimals and display the coordinates in a diff --git a/src/gtk-sat-list.h b/src/gtk-sat-list.h index 9e5689a4..b8944595 100644 --- a/src/gtk-sat-list.h +++ b/src/gtk-sat-list.h @@ -103,6 +103,7 @@ typedef enum { SAT_LIST_COL_ORBIT, /*!< Orbit Number. */ SAT_LIST_COL_VISIBILITY, /*!< Visibility. */ SAT_LIST_COL_DECAY, /*!< Whether the satellite is decayed or not. */ + SAT_LIST_COL_STAT_OPERATIONAL, /*!< Operational Status . */ SAT_LIST_COL_BOLD, /*!< Used to render the satellites above the horizon bold. */ SAT_LIST_COL_NUMBER } sat_list_col_t; @@ -134,7 +135,8 @@ typedef enum { SAT_LIST_FLAG_PHASE = 1 << SAT_LIST_COL_PHASE, /*!< Phase. */ SAT_LIST_FLAG_ORBIT = 1 << SAT_LIST_COL_ORBIT, /*!< Orbit Number. */ SAT_LIST_FLAG_VISIBILITY = 1 << SAT_LIST_COL_VISIBILITY, /*!< Visibility. */ - SAT_LIST_FLAG_DECAY = 1 << SAT_LIST_COL_DECAY /*!< Decayed. */ + SAT_LIST_FLAG_STAT_OPERATIONAL = 1 << SAT_LIST_COL_STAT_OPERATIONAL, /*!< Operational Status . */ + SAT_LIST_FLAG_DECAY = 1 << SAT_LIST_COL_DECAY /*!< Decayed. */ } sat_list_flag_t; GType gtk_sat_list_get_type(void);