1.1 --- a/gmyth/gmyth/gmyth_programinfo.c Tue Dec 15 20:48:32 2009 +0000
1.2 +++ b/gmyth/gmyth/gmyth_programinfo.c Wed Dec 16 10:06:21 2009 +0000
1.3 @@ -300,11 +300,11 @@
1.4 gmyth_string_list_append_int(slist, prog->cardid); /* 18 */
1.5 gmyth_string_list_append_int(slist, prog->inputid); /* 19 */
1.6 gmyth_string_list_append_int(slist, prog->recpriority); /* 20 */
1.7 - gmyth_string_list_append_int(slist, 0 /* prog->recstatus */ ); /* 21 */
1.8 + gmyth_string_list_append_int(slist, prog->recstatus); /* 21 */
1.9 gmyth_string_list_append_int(slist, prog->recordid); /* 22 */
1.10 - gmyth_string_list_append_int(slist, 0 /* prog->rectype */ ); /* 23 */
1.11 - gmyth_string_list_append_int(slist, 0 /* prog->dupin */ ); /* 24 */
1.12 - gmyth_string_list_append_int(slist, 0 /* prog->dupmethod */ ); /* 25 */
1.13 + gmyth_string_list_append_int(slist, prog->rectype); /* 23 */
1.14 + gmyth_string_list_append_int(slist, prog->dupin); /* 24 */
1.15 + gmyth_string_list_append_int(slist, prog->dupmethod); /* 25 */
1.16 gmyth_string_list_append_int(slist, prog->recstartts != NULL ? prog->recstartts->tv_sec : 0); /* 26
1.17 */// DATETIME_TO_LIST(recstartts)
1.18 gmyth_string_list_append_int(slist, prog->recendts != NULL ? prog->recendts->tv_sec : 0); /* 27
1.19 @@ -389,11 +389,12 @@
1.20 prog->cardid = gmyth_string_list_get_int(slist, pos + 18);
1.21 prog->inputid = gmyth_string_list_get_int(slist, pos + 19);
1.22 prog->recpriority = gmyth_string_list_get_int(slist, pos + 20);
1.23 - prog->reactivate = gmyth_string_list_get_int(slist, pos + 21);
1.24 + prog->recstatus = gmyth_string_list_get_int(slist, pos + 21);
1.25 + prog->reactivate = prog->recstatus;
1.26 prog->recordid = gmyth_string_list_get_int(slist, pos + 22);
1.27 - gmyth_string_list_get_int(slist, pos + 23);
1.28 - gmyth_string_list_get_int(slist, pos + 24);
1.29 - gmyth_string_list_get_int(slist, pos + 25);
1.30 + prog->rectype = gmyth_string_list_get_int(slist, pos + 23);
1.31 + prog->dupin = gmyth_string_list_get_int(slist, pos + 24);
1.32 + prog->dupmethod = gmyth_string_list_get_int(slist, pos + 25);
1.33 prog->recstartts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 26)))->str); // DATETIME_TO_LIST(recstartts)
1.34 prog->recendts = gmyth_util_string_to_time_val((gmyth_util_time_to_isoformat((time_t) gmyth_string_list_get_int(slist, pos + 27)))->str); // DATETIME_TO_LIST(recendts)
1.35 prog->repeat = gmyth_string_list_get_int(slist, pos + 28);
2.1 --- a/gmyth/gmyth/gmyth_programinfo.h Tue Dec 15 20:48:32 2009 +0000
2.2 +++ b/gmyth/gmyth/gmyth_programinfo.h Wed Dec 16 10:06:21 2009 +0000
2.3 @@ -53,6 +53,32 @@
2.4 */
2.5 };
2.6
2.7 +typedef enum {
2.8 + GMYTH_REC_STATUS_FAILED = -9,
2.9 + GMYTH_REC_STATUS_TUNER_BUSY = -8,
2.10 + GMYTH_REC_STATUS_LOW_DISK_SPACE = -7,
2.11 + GMYTH_REC_STATUS_CANCELLED = -6,
2.12 + GMYTH_REC_STATUS_MISSED = -5,
2.13 + GMYTH_REC_STATUS_ABORTED = -4,
2.14 + GMYTH_REC_STATUS_RECORDED = -3,
2.15 + GMYTH_REC_STATUS_RECORDING = -2,
2.16 + GMYTH_REC_STATUS_WILL_RECORD = -1,
2.17 + GMYTH_REC_STATUS_UNKNOWN = 0,
2.18 + GMYTH_REC_STATUS_DONT_RECORD = 1,
2.19 + GMYTH_REC_STATUS_PREVIOUS_RECORDING = 2,
2.20 + GMYTH_REC_STATUS_CURRENT_RECORDING = 3,
2.21 + GMYTH_REC_STATUS_EARLIER_SHOWING = 4,
2.22 + GMYTH_REC_STATUS_TOO_MANY_RECORDINGS = 5,
2.23 + GMYTH_REC_STATUS_NOT_LISTED = 6,
2.24 + GMYTH_REC_STATUS_CONFLICT = 7,
2.25 + GMYTH_REC_STATUS_LATER_SHOWING = 8,
2.26 + GMYTH_REC_STATUS_REPEAT = 9,
2.27 + GMYTH_REC_STATUS_INACTIVE = 10,
2.28 + GMYTH_REC_STATUS_NEVER_RECORD = 11,
2.29 + GMYTH_REC_STATUS_OFF_LINE = 12,
2.30 + GMYTH_REC_STATUS_OTHER_SHOWING = 13,
2.31 +} GMythRecStatus;
2.32 +
2.33 /**
2.34 * The GMythProgramInfo structure represents a program information
2.35 * stored in the database. It could be a program from the EPG data,
2.36 @@ -136,7 +162,7 @@
2.37 GString *recgroup;
2.38 GString *playgroup;
2.39 gint rectype;
2.40 - gint recstatus;
2.41 + GMythRecStatus recstatus;
2.42 gint recpriority;
2.43 gint dupin;
2.44 gint dupmethod;
3.1 --- a/gmyth/gmyth/gmyth_util.c Tue Dec 15 20:48:32 2009 +0000
3.2 +++ b/gmyth/gmyth/gmyth_util.c Wed Dec 16 10:06:21 2009 +0000
3.3 @@ -775,6 +775,50 @@
3.4 return program;
3.5 }
3.6
3.7 +GSList *
3.8 +gmyth_util_get_all_pending(GMythBackendInfo * backend_info,
3.9 + gboolean * conflicts)
3.10 +{
3.11 + GSList *program_list = NULL;
3.12 + GMythSocket *socket;
3.13 + gboolean res;
3.14 +
3.15 + socket = gmyth_socket_new();
3.16 + res = gmyth_socket_connect_to_backend(socket, backend_info->hostname,
3.17 + backend_info->port, TRUE);
3.18 +
3.19 + if (res) {
3.20 + GMythStringList *slist = gmyth_string_list_new();
3.21 + int pos, lines, count;
3.22 +
3.23 + gmyth_string_list_append_char_array(slist, "QUERY_GETALLPENDING");
3.24 +
3.25 + gmyth_socket_sendreceive_stringlist(socket, slist);
3.26 +
3.27 + if (gmyth_string_list_length(slist) > 1) {
3.28 + GMythProgramInfo *program;
3.29 +
3.30 + *conflicts = gmyth_string_list_get_int(slist, 0);
3.31 + count = gmyth_string_list_get_int(slist, 1);
3.32 + lines = (gmyth_string_list_length(slist) - 2) / count;
3.33 +
3.34 + for(pos = 2; pos < 2 + count * lines; pos += lines) {
3.35 + program =
3.36 + gmyth_program_info_from_string_list_from_pos(slist, pos);
3.37 +
3.38 + if (program)
3.39 + program_list = g_slist_prepend(program_list, program);
3.40 + }
3.41 + }
3.42 + g_object_unref(slist);
3.43 +
3.44 + gmyth_socket_close_connection(socket);
3.45 + }
3.46 + g_object_unref(socket);
3.47 +
3.48 + return g_slist_reverse(program_list);
3.49 +}
3.50 +
3.51 #if !GLIB_CHECK_VERSION (2, 10, 0)
3.52
3.53 /*
4.1 --- a/gmyth/gmyth/gmyth_util.h Tue Dec 15 20:48:32 2009 +0000
4.2 +++ b/gmyth/gmyth/gmyth_util.h Wed Dec 16 10:06:21 2009 +0000
4.3 @@ -79,6 +79,8 @@
4.4 GMythProgramInfo*
4.5 gmyth_util_get_recording_from_channel (GMythBackendInfo *backend_info,
4.6 const gchar *channel);
4.7 +GSList* gmyth_util_get_all_pending (GMythBackendInfo * backend_info,
4.8 + gboolean * conflicts);
4.9
4.10 G_END_DECLS
4.11 #endif /* GMYTH_UTIL_H_ */
5.1 --- a/gmyth/samples/gmyth_ls.c Tue Dec 15 20:48:32 2009 +0000
5.2 +++ b/gmyth/samples/gmyth_ls.c Wed Dec 16 10:06:21 2009 +0000
5.3 @@ -14,6 +14,8 @@
5.4 typedef struct {
5.5 GMythBackendInfo *b_info;
5.6 gboolean list_channels;
5.7 + gboolean list_rules;
5.8 + gboolean list_upcoming;
5.9 } ls_options_t;
5.10
5.11 static ls_options_t *
5.12 @@ -41,9 +43,8 @@
5.13 GOptionContext *context;
5.14
5.15 gchar *host_ip = NULL;
5.16 - gint host_port = 0;
5.17 + gint host_port = 6543;
5.18 gint db_port = 0;
5.19 - gboolean list_channels = FALSE;
5.20 gchar *username = NULL;
5.21 gchar *password = NULL;
5.22
5.23 @@ -55,11 +56,16 @@
5.24 "Mythtv backend port",
5.25 "PORT"},
5.26
5.27 - {"list_channels", 'c', 0, G_OPTION_ARG_NONE, &list_channels,
5.28 - "List channels",
5.29 - "LIST_CHANNELS"},
5.30 + {"list_channels", 'c', 0, G_OPTION_ARG_NONE, &options->list_channels,
5.31 + "List channels", NULL},
5.32
5.33 - {"username", 'u', 0, G_OPTION_ARG_STRING, &username,
5.34 + {"list_rules", 'r', 0, G_OPTION_ARG_NONE, &options->list_rules,
5.35 + "List recording rules", NULL},
5.36 +
5.37 + {"list_upcoming", 'u', 0, G_OPTION_ARG_NONE, &options->list_upcoming,
5.38 + "List upcoming recordings", NULL},
5.39 +
5.40 + {"username", 'n', 0, G_OPTION_ARG_STRING, &username,
5.41 "Mysql database username. Default: mythtv",
5.42 "MYSQL_USER"},
5.43
5.44 @@ -76,21 +82,28 @@
5.45
5.46 g_return_val_if_fail(options != NULL, FALSE);
5.47
5.48 - context =
5.49 - g_option_context_new
5.50 - ("- list recorded programs and channels from a mythtv backend\n");
5.51 + context = g_option_context_new("- list mythtv recorded programs etc.");
5.52 g_option_context_add_main_entries(context, entries, NULL);
5.53 g_option_context_parse(context, &argc, &argv, &error);
5.54 - g_option_context_set_help_enabled(context, TRUE);
5.55
5.56 g_option_context_free(context);
5.57
5.58 - if ((!host_ip) || (host_port == 0)) {
5.59 + if (error) {
5.60 + g_printerr("%s.\n", error->message);
5.61 + g_error_free(error);
5.62 g_free(host_ip);
5.63 return FALSE;
5.64 }
5.65
5.66 - gmyth_backend_info_set_hostname(options->b_info, host_ip);
5.67 + if (!!options->list_channels + !!options->list_rules +
5.68 + !!options->list_upcoming > 1) {
5.69 + g_printerr("Only one --list option may be given.\n");
5.70 + g_free(host_ip);
5.71 + return FALSE;
5.72 + }
5.73 +
5.74 + gmyth_backend_info_set_hostname(options->b_info,
5.75 + host_ip ? host_ip : "localhost");
5.76 gmyth_backend_info_set_port(options->b_info, host_port);
5.77
5.78 if (username)
5.79 @@ -105,9 +118,105 @@
5.80
5.81 gmyth_backend_info_set_db_name(options->b_info, "mythconverg");
5.82
5.83 - options->list_channels = list_channels;
5.84 + g_free(host_ip);
5.85
5.86 - g_free(host_ip);
5.87 + return TRUE;
5.88 +}
5.89 +
5.90 +static gboolean
5.91 +_ls_recording_rules(ls_options_t * options)
5.92 +{
5.93 + GMythScheduler *scheduler;
5.94 + GList *list,
5.95 + *iter;
5.96 + gint res = 0,
5.97 + count = 0;
5.98 +
5.99 + g_return_val_if_fail(options != NULL, FALSE);
5.100 + g_return_val_if_fail(options->b_info != NULL, FALSE);
5.101 +
5.102 + scheduler = gmyth_scheduler_new();
5.103 +
5.104 + if (gmyth_scheduler_connect_with_timeout(scheduler,
5.105 + options->b_info, 10) == FALSE)
5.106 + {
5.107 + g_print("Could not connect to database server.\n");
5.108 + g_object_unref(scheduler);
5.109 + return FALSE;
5.110 + }
5.111 +
5.112 + res = gmyth_scheduler_get_schedule_list(scheduler, &list);
5.113 +
5.114 + gmyth_scheduler_disconnect(scheduler);
5.115 + g_object_unref(scheduler);
5.116 +
5.117 + if (res < 0) {
5.118 + g_print("Could not retrieve list of recording rules.\n");
5.119 + return FALSE;
5.120 + }
5.121 +
5.122 + iter = list;
5.123 + while (iter) {
5.124 + ScheduleInfo *schedule_info = (ScheduleInfo *) iter->data;
5.125 +
5.126 + count++;
5.127 + g_print("%s\n", schedule_info->title->str);
5.128 + gmyth_schedule_info_free(schedule_info);
5.129 + iter = g_list_next(iter);
5.130 + }
5.131 +
5.132 + if (!count)
5.133 + g_print("No recording rules.\n");
5.134 +
5.135 + g_list_free(list);
5.136 +
5.137 + return TRUE;
5.138 +}
5.139 +
5.140 +static gboolean
5.141 +_ls_upcoming_recordings(ls_options_t * options)
5.142 +{
5.143 + GSList *list,
5.144 + *iter;
5.145 + gint count = 0;
5.146 + gboolean conflicts;
5.147 + time_t recstart;
5.148 + struct tm *tm;
5.149 + char buffer[64];
5.150 +
5.151 + g_return_val_if_fail(options != NULL, FALSE);
5.152 + g_return_val_if_fail(options->b_info != NULL, FALSE);
5.153 +
5.154 + list = gmyth_util_get_all_pending(options->b_info, &conflicts);
5.155 +
5.156 + iter = list;
5.157 + while (iter) {
5.158 + GMythProgramInfo *program = (GMythProgramInfo *) iter->data;
5.159 +
5.160 + if (program->recstatus == GMYTH_REC_STATUS_RECORDING ||
5.161 + program->recstatus == GMYTH_REC_STATUS_WILL_RECORD) {
5.162 + count++;
5.163 + recstart = program->recstartts->tv_sec;
5.164 + tm = localtime(&recstart);
5.165 + strftime(buffer, sizeof(buffer), "%F %R", tm);
5.166 + g_print("%s %s", buffer, program->title->str);
5.167 + if (program->subtitle->len)
5.168 + g_print(": %s", program->subtitle->str);
5.169 + g_print("\n");
5.170 + }
5.171 +
5.172 + g_object_unref(program);
5.173 + iter = g_slist_next(iter);
5.174 + }
5.175 +
5.176 + if (!count)
5.177 + g_print("No upcoming recordings.\n");
5.178 + else if (conflicts)
5.179 + g_print("Conflicts found.\n");
5.180 + else
5.181 + g_print("No conflicts found.\n");
5.182 +
5.183 + g_slist_free(list);
5.184
5.185 return TRUE;
5.186 }
5.187 @@ -232,6 +341,10 @@
5.188
5.189 if (options->list_channels)
5.190 res = _ls_channels(options);
5.191 + else if (options->list_rules)
5.192 + res = _ls_recording_rules(options);
5.193 + else if (options->list_upcoming)
5.194 + res = _ls_upcoming_recordings(options);
5.195 else
5.196 res = _ls_recorded_files(options);
5.197