gmyth/src/gmyth_scheduler.c
author renatofilho
Tue Jan 29 18:40:18 2008 +0000 (2008-01-29)
branchtrunk
changeset 895 4bdd0f922b68
parent 890 6b565181036e
permissions -rw-r--r--
[svn r901] fixed var names
leo_sobral@1
     1
/**
leo_sobral@1
     2
 * GMyth Library
leo_sobral@1
     3
 *
leo_sobral@1
     4
 * @file gmyth/gmyth_scheduler.c
renatofilho@771
     5
 *
leo_sobral@1
     6
 * @brief <p> The scheduler encapsulates all functions for browsing, scheduling
leo_sobral@1
     7
 * and modifying the recorded content.
leo_sobral@1
     8
 *
leo_sobral@1
     9
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
leo_sobral@1
    10
 * @author Alexsandro Jose Virginio dos Santos <alexsandro.santos@indt.org.br>
leo_sobral@1
    11
 *
renatofilho@771
    12
 *
rosfran@701
    13
 * This program is free software; you can redistribute it and/or modify
rosfran@701
    14
 * it under the terms of the GNU Lesser General Public License as published by
rosfran@701
    15
 * the Free Software Foundation; either version 2 of the License, or
rosfran@701
    16
 * (at your option) any later version.
rosfran@701
    17
 *
rosfran@701
    18
 * This program is distributed in the hope that it will be useful,
rosfran@701
    19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rosfran@701
    20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rosfran@701
    21
 * GNU General Public License for more details.
rosfran@701
    22
 *
rosfran@701
    23
 * You should have received a copy of the GNU Lesser General Public License
rosfran@701
    24
 * along with this program; if not, write to the Free Software
rosfran@701
    25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
rosfran@701
    26
 */
rosfran@698
    27
leo_sobral@213
    28
#ifdef HAVE_CONFIG_H
leo_sobral@213
    29
#include "config.h"
leo_sobral@213
    30
#endif
leo_sobral@1
    31
leo_sobral@213
    32
#include <assert.h>
leo_sobral@1
    33
renatofilho@890
    34
#include <glib.h>
rosfran@214
    35
#include <glib/gprintf.h>
rosfran@214
    36
rosfran@214
    37
#include "gmyth_scheduler.h"
leo_sobral@1
    38
#include "gmyth_util.h"
leo_sobral@1
    39
#include "gmyth_query.h"
melunko@117
    40
#include "gmyth_socket.h"
renatofilho@131
    41
#include "gmyth_debug.h"
leo_sobral@1
    42
renatofilho@754
    43
static void     gmyth_scheduler_class_init(GMythSchedulerClass * klass);
renatofilho@754
    44
static void     gmyth_scheduler_init(GMythScheduler * object);
leo_sobral@1
    45
renatofilho@754
    46
static void     gmyth_scheduler_dispose(GObject * object);
renatofilho@754
    47
static void     gmyth_scheduler_finalize(GObject * object);
leo_sobral@1
    48
renatofilho@750
    49
static gboolean update_backend(GMythScheduler * scheduler, gint record_id);
leo_sobral@1
    50
renatofilho@750
    51
G_DEFINE_TYPE(GMythScheduler, gmyth_scheduler, G_TYPE_OBJECT)
renatofilho@754
    52
    static void     gmyth_scheduler_class_init(GMythSchedulerClass * klass)
leo_sobral@1
    53
{
renatofilho@754
    54
    GObjectClass   *gobject_class;
leo_sobral@1
    55
renatofilho@754
    56
    gobject_class = (GObjectClass *) klass;
leo_sobral@1
    57
renatofilho@754
    58
    gobject_class->dispose = gmyth_scheduler_dispose;
renatofilho@754
    59
    gobject_class->finalize = gmyth_scheduler_finalize;
leo_sobral@1
    60
}
leo_sobral@1
    61
leo_sobral@1
    62
static void
renatofilho@750
    63
gmyth_scheduler_init(GMythScheduler * sched)
leo_sobral@1
    64
{
renatofilho@754
    65
    sched->recordid = 0;
renatofilho@754
    66
    sched->type = 0;
renatofilho@754
    67
    sched->search = 0;
renatofilho@754
    68
    sched->profile = g_string_new("");
rosfran@698
    69
renatofilho@754
    70
    sched->dupin = 0;
renatofilho@754
    71
    sched->dupmethod = 0;
renatofilho@754
    72
    sched->autoexpire = 0;
renatofilho@754
    73
    sched->autotranscode = 0;
renatofilho@754
    74
    sched->transcoder = 0;
leo_sobral@1
    75
renatofilho@754
    76
    sched->autocommflag = 0;
renatofilho@754
    77
    sched->autouserjob1 = 0;
renatofilho@754
    78
    sched->autouserjob2 = 0;
renatofilho@754
    79
    sched->autouserjob3 = 0;
renatofilho@754
    80
    sched->autouserjob4 = 0;
rosfran@698
    81
renatofilho@754
    82
    sched->startoffset = 0;
renatofilho@754
    83
    sched->endoffset = 0;
renatofilho@754
    84
    sched->maxepisodes = 0;
renatofilho@754
    85
    sched->maxnewest = 0;
leo_sobral@1
    86
renatofilho@754
    87
    sched->recpriority = 0;
renatofilho@754
    88
    sched->recgroup = g_string_new("");
renatofilho@754
    89
    sched->playgroup = g_string_new("");
rosfran@698
    90
renatofilho@754
    91
    sched->prefinput = 0;
renatofilho@754
    92
    sched->inactive = 0;
rosfran@698
    93
renatofilho@754
    94
    sched->search_type = g_string_new("");
renatofilho@754
    95
    sched->search_what = g_string_new("");
rosfran@698
    96
renatofilho@754
    97
    sched->msqlquery = gmyth_query_new();
leo_sobral@1
    98
}
leo_sobral@1
    99
leo_sobral@1
   100
static void
renatofilho@750
   101
gmyth_scheduler_dispose(GObject * object)
leo_sobral@1
   102
{
renatofilho@754
   103
    GMythScheduler *scheduler = GMYTH_SCHEDULER(object);
melunko@117
   104
renatofilho@754
   105
    if (scheduler->backend_info) {
renatofilho@754
   106
        g_object_unref(scheduler->backend_info);
renatofilho@754
   107
        scheduler->backend_info = NULL;
renatofilho@754
   108
    }
melunko@117
   109
renatofilho@754
   110
    if (scheduler->msqlquery) {
renatofilho@754
   111
        g_object_unref(scheduler->msqlquery);
renatofilho@754
   112
        scheduler->msqlquery = NULL;
renatofilho@754
   113
    }
leo_sobral@387
   114
renatofilho@754
   115
    g_string_free(scheduler->profile, TRUE);
renatofilho@754
   116
    g_string_free(scheduler->recgroup, TRUE);
renatofilho@754
   117
    g_string_free(scheduler->playgroup, TRUE);
renatofilho@754
   118
    g_string_free(scheduler->search_type, TRUE);
renatofilho@754
   119
    g_string_free(scheduler->search_what, TRUE);
leo_sobral@387
   120
renatofilho@754
   121
    G_OBJECT_CLASS(gmyth_scheduler_parent_class)->dispose(object);
leo_sobral@1
   122
}
leo_sobral@1
   123
leo_sobral@1
   124
static void
renatofilho@750
   125
gmyth_scheduler_finalize(GObject * object)
leo_sobral@1
   126
{
renatofilho@754
   127
    g_signal_handlers_destroy(object);
leo_sobral@1
   128
renatofilho@754
   129
    G_OBJECT_CLASS(gmyth_scheduler_parent_class)->finalize(object);
leo_sobral@1
   130
}
leo_sobral@1
   131
leo_sobral@1
   132
/** Creates a new instance of GMythScheduler.
leo_sobral@1
   133
 * 
leo_sobral@1
   134
 * @return a new instance of GMythScheduler.
leo_sobral@1
   135
 */
rosfran@698
   136
GMythScheduler *
renatofilho@750
   137
gmyth_scheduler_new()
leo_sobral@1
   138
{
renatofilho@754
   139
    GMythScheduler *scheduler =
renatofilho@754
   140
        GMYTH_SCHEDULER(g_object_new(GMYTH_SCHEDULER_TYPE, NULL));
rosfran@698
   141
renatofilho@754
   142
    return scheduler;
leo_sobral@1
   143
}
leo_sobral@1
   144
melunko@257
   145
gboolean
renatofilho@750
   146
gmyth_scheduler_connect(GMythScheduler * scheduler,
renatofilho@754
   147
                        GMythBackendInfo * backend_info)
melunko@257
   148
{
renatofilho@754
   149
    return gmyth_scheduler_connect_with_timeout(scheduler, backend_info,
renatofilho@754
   150
                                                0);
melunko@257
   151
}
melunko@257
   152
leo_sobral@1
   153
/** Connects to the Mysql database in the backend. The backend address
leo_sobral@1
   154
 * is loaded from the GMythSettings instance.
morphbr@766
   155
 *
leo_sobral@1
   156
 * @param scheduler the GMythScheduler instance to be connected.
leo_sobral@1
   157
 * @return true if connection was success, false if failed.
leo_sobral@1
   158
 */
leo_sobral@1
   159
gboolean
renatofilho@750
   160
gmyth_scheduler_connect_with_timeout(GMythScheduler * scheduler,
renatofilho@754
   161
                                     GMythBackendInfo * backend_info,
renatofilho@754
   162
                                     guint timeout)
leo_sobral@1
   163
{
renatofilho@754
   164
    assert(scheduler);
renatofilho@754
   165
    g_return_val_if_fail(backend_info != NULL, FALSE);
rosfran@698
   166
renatofilho@754
   167
    if (scheduler->backend_info)
renatofilho@754
   168
        g_object_unref(scheduler->backend_info);
rosfran@698
   169
renatofilho@754
   170
    scheduler->backend_info = g_object_ref(backend_info);
leo_sobral@1
   171
renatofilho@754
   172
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   173
        g_warning("[%s] GMythScheduler db initializing", __FUNCTION__);
renatofilho@754
   174
        scheduler->msqlquery = gmyth_query_new();
renatofilho@754
   175
    }
leo_sobral@1
   176
renatofilho@754
   177
    if (!gmyth_query_connect_with_timeout(scheduler->msqlquery,
renatofilho@754
   178
                                          scheduler->backend_info,
renatofilho@754
   179
                                          timeout)) {
renatofilho@754
   180
        g_warning("[%s] Error while connecting to db", __FUNCTION__);
renatofilho@754
   181
        return FALSE;
renatofilho@754
   182
    }
leo_sobral@1
   183
renatofilho@754
   184
    return TRUE;
leo_sobral@1
   185
}
leo_sobral@1
   186
leo_sobral@1
   187
/** Disconnects from the Mysql database in the backend.
morphbr@766
   188
 *
leo_sobral@1
   189
 * @param scheduler the GMythScheduler instance to be disconnected
leo_sobral@1
   190
 * @return true if disconnection was success, false if failed.
leo_sobral@1
   191
 */
leo_sobral@1
   192
gboolean
renatofilho@750
   193
gmyth_scheduler_disconnect(GMythScheduler * scheduler)
leo_sobral@1
   194
{
renatofilho@754
   195
    assert(scheduler);
leo_sobral@1
   196
renatofilho@754
   197
    if (scheduler->msqlquery != NULL) {
renatofilho@754
   198
        gmyth_query_disconnect(scheduler->msqlquery);
renatofilho@754
   199
    }
leo_sobral@1
   200
renatofilho@754
   201
    return TRUE;
leo_sobral@1
   202
}
leo_sobral@1
   203
leo_sobral@1
   204
/** Retrieves from the backend Mysql database the list of recording schedules.
leo_sobral@1
   205
 * 
leo_sobral@1
   206
 * @param scheduler The GMythScheduler instance.
leo_sobral@1
   207
 * @param schedule_list the GList pointer to be filled with the loaded list of ScheduleInfo items.
leo_sobral@1
   208
 * @return The amount of schedules retrieved from database, or -1 if error.
leo_sobral@1
   209
 */
leo_sobral@1
   210
gint
renatofilho@750
   211
gmyth_scheduler_get_schedule_list(GMythScheduler * scheduler,
renatofilho@754
   212
                                  GList ** schedule_list)
leo_sobral@1
   213
{
renatofilho@754
   214
    ScheduleInfo   *schedule;
renatofilho@754
   215
    MYSQL_RES      *msql_res;
renatofilho@754
   216
    GString        *query_str = g_string_new("");
renatofilho@754
   217
    gchar          *date_time = NULL;
rosfran@698
   218
renatofilho@754
   219
    assert(scheduler);
rosfran@698
   220
renatofilho@754
   221
    g_string_printf(query_str,
renatofilho@754
   222
                    "SELECT recordid,programid,chanid,starttime,startdate,"
renatofilho@886
   223
                    "endtime,enddate,title,subtitle,description,category,type,parentid,seriesid FROM record;");
leo_sobral@1
   224
renatofilho@754
   225
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   226
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   227
                  __FUNCTION__);
renatofilho@754
   228
        return -1;
renatofilho@754
   229
    }
renatofilho@754
   230
    msql_res =
renatofilho@754
   231
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@754
   232
                                      query_str->str);
leo_sobral@1
   233
renatofilho@754
   234
    if (msql_res == NULL) {
renatofilho@754
   235
        g_warning("DB retrieval of schedule list failed");
renatofilho@754
   236
        return -1;
renatofilho@754
   237
    } else {
renatofilho@754
   238
        MYSQL_ROW       row;
rosfran@698
   239
renatofilho@754
   240
        *schedule_list = NULL;
rosfran@698
   241
renatofilho@754
   242
        while ((row = mysql_fetch_row(msql_res)) != NULL) {
renatofilho@754
   243
            schedule = g_new0(ScheduleInfo, 1);
melunko@836
   244
            gint type = 0;
rosfran@698
   245
renatofilho@754
   246
            schedule->schedule_id =
renatofilho@754
   247
                (guint) g_ascii_strtoull(row[0], NULL, 10);
renatofilho@895
   248
            schedule->program_id = g_string_new (row[1]);
renatofilho@895
   249
            schedule->channel_id = (gint) g_ascii_strtoull (row[2], NULL, 10);
rosfran@698
   250
renatofilho@754
   251
            /*
renatofilho@754
   252
             * generate a time_t from a time and a date db field 
renatofilho@754
   253
             */
renatofilho@754
   254
            date_time = g_strdup_printf("%sT%s", row[4], row[3]);
renatofilho@754
   255
            schedule->start_time =
renatofilho@754
   256
                gmyth_util_string_to_time_val(date_time);
renatofilho@754
   257
            g_free(date_time);
rosfran@698
   258
renatofilho@754
   259
            /*
renatofilho@754
   260
             * generate a time_t from a time and a date db field 
renatofilho@754
   261
             */
renatofilho@754
   262
            date_time = g_strdup_printf("%sT%s", row[6], row[5]);
renatofilho@754
   263
            schedule->end_time = gmyth_util_string_to_time_val(date_time);
renatofilho@754
   264
            g_free(date_time);
leo_sobral@1
   265
renatofilho@754
   266
            schedule->title = g_string_new(row[7]);
renatofilho@754
   267
            schedule->subtitle = g_string_new(row[8]);
renatofilho@754
   268
            schedule->description = g_string_new(row[9]);
renatofilho@754
   269
            schedule->category = g_string_new(row[10]);
melunko@836
   270
            type = g_ascii_strtoull (row[11], NULL, 10);
melunko@836
   271
            if (type == 4) {
melunko@836
   272
                schedule->type = GMYTH_SCHEDULE_ALL_OCCURRENCES;
melunko@836
   273
            } else if (type == 1) {
melunko@836
   274
                schedule->type = GMYTH_SCHEDULE_ONE_OCCURRENCE;
melunko@836
   275
            } else if (type == 8) {
melunko@836
   276
                schedule->type = GMYTH_SCHEDULE_EXCEPTION;
melunko@836
   277
                schedule->parentid = (gint) g_ascii_strtoull (row[12], NULL, 10);
melunko@836
   278
            }
leo_sobral@1
   279
renatofilho@886
   280
            schedule->seriesid = g_string_new (row[13]);
renatofilho@886
   281
renatofilho@754
   282
            (*schedule_list) = g_list_append(*(schedule_list), schedule);
renatofilho@754
   283
        }
renatofilho@754
   284
    }
leo_sobral@1
   285
renatofilho@754
   286
    mysql_free_result(msql_res);
renatofilho@754
   287
    g_string_free(query_str, TRUE);
leo_sobral@1
   288
renatofilho@754
   289
    return (*schedule_list == NULL) ? 0 : g_list_length(*schedule_list);
leo_sobral@1
   290
}
leo_sobral@1
   291
leo_sobral@1
   292
/** Retrieves from the backend Mysql database the list of recorded programs.
leo_sobral@1
   293
 * 
leo_sobral@1
   294
 * @param scheduler The GMythScheduler instance.
leo_sobral@1
   295
 * @param recorded_list the GList pointer to be filled with the loaded RecordInfo items.
leo_sobral@1
   296
 * @return The amount of recorded retrieved from database, or -1 if error.
leo_sobral@1
   297
 */
leo_sobral@1
   298
gint
renatofilho@750
   299
gmyth_scheduler_get_recorded_list(GMythScheduler * scheduler,
renatofilho@754
   300
                                  GList ** recorded_list)
leo_sobral@1
   301
{
renatofilho@754
   302
    RecordedInfo   *record;
renatofilho@754
   303
    MYSQL_RES      *msql_res;
renatofilho@754
   304
    GString        *query_str = g_string_new("");
rosfran@698
   305
renatofilho@754
   306
    assert(scheduler);
rosfran@698
   307
renatofilho@754
   308
    g_string_printf(query_str,
renatofilho@754
   309
                    "SELECT recordid,programid,chanid,starttime,progstart,"
renatofilho@754
   310
                    "endtime,progend,title,subtitle,description,category,"
renatofilho@886
   311
                    "filesize,basename,seriesid FROM recorded WHERE recgroup != 'LiveTV'");
leo_sobral@1
   312
renatofilho@754
   313
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   314
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   315
                  __FUNCTION__);
renatofilho@754
   316
        return -1;
renatofilho@754
   317
    }
leo_sobral@1
   318
renatofilho@754
   319
    msql_res =
renatofilho@754
   320
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@754
   321
                                      query_str->str);
leo_sobral@1
   322
renatofilho@754
   323
    if (msql_res == NULL) {
renatofilho@754
   324
        g_warning("DB retrieval of recording list failed");
renatofilho@754
   325
        return -1;
renatofilho@754
   326
    } else {
renatofilho@754
   327
        MYSQL_ROW       row;
rosfran@698
   328
renatofilho@754
   329
        (*recorded_list) = NULL;
rosfran@698
   330
renatofilho@754
   331
        while ((row = mysql_fetch_row(msql_res)) != NULL) {
renatofilho@754
   332
            record = g_new0(RecordedInfo, 1);
rosfran@698
   333
renatofilho@754
   334
            record->record_id = (guint) g_ascii_strtoull(row[0], NULL, 10);
renatofilho@895
   335
            record->program_id = g_string_new (row[1]);
renatofilho@895
   336
            record->channel_id = (gint) g_ascii_strtoull(row[2], NULL, 10);
renatofilho@754
   337
            record->start_time = gmyth_util_string_to_time_val(row[3]);
renatofilho@754
   338
            record->end_time = gmyth_util_string_to_time_val(row[5]);
rosfran@698
   339
renatofilho@754
   340
            record->title = g_string_new(row[7]);
renatofilho@754
   341
            record->subtitle = g_string_new(row[8]);
renatofilho@754
   342
            record->description = g_string_new(row[9]);
renatofilho@754
   343
            record->category = g_string_new(row[10]);
renatofilho@754
   344
            record->filesize = g_ascii_strtoull(row[11], NULL, 10);
renatofilho@754
   345
            record->basename = g_string_new(row[12]);
renatofilho@886
   346
            record->seriesid = g_string_new(row[13]);
leo_sobral@1
   347
renatofilho@754
   348
            (*recorded_list) = g_list_append((*recorded_list), record);
renatofilho@754
   349
        }
renatofilho@754
   350
    }
rosfran@698
   351
renatofilho@754
   352
    mysql_free_result(msql_res);
renatofilho@754
   353
    g_string_free(query_str, TRUE);
leo_sobral@1
   354
renatofilho@754
   355
    return (*recorded_list == NULL) ? 0 : g_list_length(*recorded_list);
leo_sobral@1
   356
}
leo_sobral@1
   357
renatofilho@771
   358
RecordedInfo*
renatofilho@755
   359
gmyth_scheduler_get_recorded_info (GMythScheduler *scheduler,
renatofilho@771
   360
                                   const gchar* basename)
renatofilho@755
   361
{
renatofilho@769
   362
    RecordedInfo   *record = NULL;
renatofilho@755
   363
    MYSQL_RES      *msql_res;
renatofilho@755
   364
    GString        *query_str = g_string_new("");
renatofilho@755
   365
renatofilho@755
   366
    assert(scheduler);
renatofilho@755
   367
renatofilho@755
   368
    g_string_printf(query_str,
renatofilho@755
   369
                    "SELECT recordid,programid,chanid,starttime,progstart,"
renatofilho@755
   370
                    "endtime,progend,title,subtitle,description,category,"
renatofilho@886
   371
                    "filesize,basename,seriesid FROM recorded "
renatofilho@771
   372
                    "WHERE recgroup != 'LiveTV' AND basename = '%s'", basename);
renatofilho@755
   373
renatofilho@755
   374
    if (scheduler->msqlquery == NULL) {
renatofilho@755
   375
        g_warning("[%s] Scheduler db connection not initialized", 
renatofilho@755
   376
                        __FUNCTION__);
renatofilho@769
   377
        return NULL;
renatofilho@755
   378
    }
renatofilho@755
   379
renatofilho@755
   380
    msql_res =
renatofilho@755
   381
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@755
   382
                                      query_str->str);
renatofilho@755
   383
renatofilho@755
   384
    if (msql_res == NULL) {
renatofilho@755
   385
        g_warning("DB retrieval of recording list failed");
renatofilho@769
   386
        return NULL;
renatofilho@755
   387
    } else {
renatofilho@755
   388
        MYSQL_ROW       row;
renatofilho@755
   389
        row = mysql_fetch_row(msql_res);
renatofilho@755
   390
        if (row != NULL) {
renatofilho@755
   391
            record = g_new0(RecordedInfo, 1);
renatofilho@755
   392
            record->record_id = (guint) g_ascii_strtoull(row[0], NULL, 10);
renatofilho@895
   393
            record->program_id = g_string_new (row[1]);
renatofilho@895
   394
            record->channel_id = (gint) g_ascii_strtoull(row[2], NULL, 10);
renatofilho@755
   395
            record->start_time = gmyth_util_string_to_time_val(row[3]);
renatofilho@755
   396
            record->end_time = gmyth_util_string_to_time_val(row[5]);
renatofilho@755
   397
            record->title = g_string_new(row[7]);
renatofilho@755
   398
            record->subtitle = g_string_new(row[8]);
renatofilho@755
   399
            record->description = g_string_new(row[9]);
renatofilho@755
   400
            record->category = g_string_new(row[10]);
renatofilho@755
   401
            record->filesize = g_ascii_strtoull(row[11], NULL, 10);
renatofilho@755
   402
            record->basename = g_string_new(row[12]);
renatofilho@886
   403
            record->seriesid = g_string_new(row[13]);
renatofilho@755
   404
        }
renatofilho@755
   405
    }
renatofilho@755
   406
renatofilho@755
   407
    mysql_free_result(msql_res);
renatofilho@755
   408
    g_string_free(query_str, TRUE);
renatofilho@755
   409
renatofilho@755
   410
    return record;
renatofilho@755
   411
}
renatofilho@755
   412
renatofilho@755
   413
melunko@567
   414
static void
renatofilho@754
   415
_set_value(GMythQuery * myth_query, char *field, gchar * value,
renatofilho@754
   416
           gint rec_id)
melunko@567
   417
{
renatofilho@754
   418
    gchar          *query =
renatofilho@754
   419
        g_strdup_printf
renatofilho@754
   420
        ("UPDATE record SET recordid = %d, %s = \"%s\" WHERE recordid = %d;",
renatofilho@754
   421
         rec_id, field, value, rec_id);
melunko@567
   422
renatofilho@754
   423
    gmyth_query_process_statement(myth_query, query);
renatofilho@754
   424
    g_free(query);
melunko@567
   425
}
melunko@567
   426
melunko@567
   427
static void
renatofilho@754
   428
_set_int_value(GMythQuery * myth_query, char *field, gint value,
renatofilho@754
   429
               gint rec_id)
melunko@567
   430
{
melunko@814
   431
    gchar *str_value = g_strdup_printf("%d", value);
rosfran@698
   432
renatofilho@754
   433
    _set_value(myth_query, field, str_value, rec_id);
renatofilho@754
   434
    g_free(str_value);
melunko@567
   435
}
melunko@567
   436
renatofilho@886
   437
ScheduleInfo*
renatofilho@886
   438
gmyth_scheduler_add_schedule_program (GMythScheduler * scheduler,
renatofilho@886
   439
                                      GMythProgramInfo *program,
renatofilho@886
   440
                                      GMythScheduleType type)
renatofilho@886
   441
{
renatofilho@886
   442
    ScheduleInfo *info;
renatofilho@886
   443
renatofilho@886
   444
    info = g_new0 (ScheduleInfo, 1);
renatofilho@895
   445
    info->program_id = g_string_new (program->program_id->str);
renatofilho@895
   446
    info->channel_id = program->channel_id;
renatofilho@886
   447
    info->start_time = g_new0 (GTimeVal, 1);
renatofilho@886
   448
    *info->start_time = *program->startts;
renatofilho@886
   449
    info->end_time = g_new0 (GTimeVal, 1);
renatofilho@886
   450
    *info->end_time = *program->endts;
renatofilho@886
   451
    info->seriesid = g_string_new (program->seriesid->str);
renatofilho@886
   452
    info->title = g_string_new (program->title->str);
renatofilho@886
   453
    info->subtitle = g_string_new (program->subtitle->str);
renatofilho@886
   454
    info->description = g_string_new (program->description->str);
renatofilho@886
   455
    info->category = g_string_new (program->category->str);
renatofilho@886
   456
    info->type = type;
renatofilho@886
   457
renatofilho@886
   458
    if (gmyth_scheduler_add_schedule_full (scheduler, info, type))
renatofilho@886
   459
    {
renatofilho@886
   460
        if (!program->recstartts)
renatofilho@886
   461
            program->recstartts = g_new0 (GTimeVal, 1);
renatofilho@886
   462
        *program->recstartts = *info->start_time;
renatofilho@886
   463
renatofilho@886
   464
        if (!program->recendts)
renatofilho@886
   465
            program->recendts = g_new0 (GTimeVal, 1);
renatofilho@886
   466
        *program->recendts = *info->end_time;
renatofilho@886
   467
renatofilho@886
   468
        program->recordid = info->schedule_id;
renatofilho@886
   469
        return info;
renatofilho@886
   470
    }
renatofilho@886
   471
renatofilho@886
   472
    gmyth_schedule_info_free (info);
renatofilho@886
   473
    return NULL;
renatofilho@886
   474
}
renatofilho@886
   475
renatofilho@886
   476
leo_sobral@1
   477
gboolean
melunko@801
   478
gmyth_scheduler_add_schedule_full (GMythScheduler * scheduler,
melunko@801
   479
                             ScheduleInfo * schedule_info, GMythScheduleType type)
leo_sobral@1
   480
{
renatofilho@754
   481
    MYSQL_RES      *msql_res;
renatofilho@754
   482
    gchar          *query_str = "INSERT record (recordid) VALUE (0);";
renatofilho@754
   483
    gchar          *station = NULL;
renatofilho@754
   484
    gulong          rec_id;
rosfran@698
   485
renatofilho@890
   486
    g_return_val_if_fail (IS_GMYTH_SCHEDULER (scheduler), FALSE);
rosfran@698
   487
renatofilho@754
   488
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   489
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   490
                  __FUNCTION__);
renatofilho@754
   491
        return FALSE;
renatofilho@754
   492
    }
melunko@567
   493
renatofilho@754
   494
    msql_res =
renatofilho@754
   495
        gmyth_query_process_statement_with_increment(scheduler->msqlquery,
renatofilho@754
   496
                                                     query_str, &rec_id);
renatofilho@754
   497
    mysql_free_result(msql_res);
rosfran@698
   498
renatofilho@754
   499
    // Retrieves the station info
renatofilho@754
   500
    query_str =
renatofilho@754
   501
        g_strdup_printf
renatofilho@890
   502
        ("SELECT callsign FROM channel WHERE chanid = %d;",
renatofilho@895
   503
         schedule_info->channel_id);
renatofilho@754
   504
    msql_res =
renatofilho@754
   505
        gmyth_query_process_statement(scheduler->msqlquery, query_str);
renatofilho@754
   506
    if (msql_res == NULL) {
renatofilho@754
   507
        g_warning("[%s] msql query returned NULL MYSQL_RES", __FUNCTION__);
renatofilho@754
   508
        return FALSE;
renatofilho@754
   509
    } else {
renatofilho@754
   510
        MYSQL_ROW       row;
rosfran@698
   511
renatofilho@754
   512
        if ((row = mysql_fetch_row(msql_res)) != NULL) {
renatofilho@754
   513
            station = g_strdup(row[0]);
renatofilho@754
   514
        }
renatofilho@754
   515
    }
renatofilho@754
   516
    mysql_free_result(msql_res);
renatofilho@754
   517
    g_free(query_str);
leo_sobral@1
   518
renatofilho@754
   519
    // _set_value (field, value, id);
renatofilho@890
   520
    _set_int_value(scheduler->msqlquery, "chanid",
renatofilho@895
   521
                   schedule_info->channel_id, rec_id);
renatofilho@754
   522
    _set_value(scheduler->msqlquery, "station", station, rec_id);
renatofilho@754
   523
    _set_value(scheduler->msqlquery, "title", schedule_info->title->str,
renatofilho@754
   524
               rec_id);
renatofilho@754
   525
    // / subtitle, description 
renatofilho@754
   526
    _set_value(scheduler->msqlquery, "starttime",
renatofilho@754
   527
               gmyth_util_time_to_string_only_time(schedule_info->
renatofilho@754
   528
                                                   start_time), rec_id);
renatofilho@754
   529
    _set_value(scheduler->msqlquery, "startdate",
renatofilho@754
   530
               gmyth_util_time_to_string_only_date(schedule_info->
renatofilho@754
   531
                                                   start_time), rec_id);
renatofilho@754
   532
    _set_value(scheduler->msqlquery, "endtime",
renatofilho@754
   533
               gmyth_util_time_to_string_only_time(schedule_info->
renatofilho@754
   534
                                                   end_time), rec_id);
renatofilho@754
   535
    _set_value(scheduler->msqlquery, "enddate",
renatofilho@754
   536
               gmyth_util_time_to_string_only_date(schedule_info->
renatofilho@754
   537
                                                   end_time), rec_id);
renatofilho@754
   538
    // / category, series id, program id
renatofilho@754
   539
    // _set_value (scheduler->msqlquery, "findday",
renatofilho@754
   540
    // (gmyth_util_time_val_to_date( schedule_info->start_time
renatofilho@754
   541
    // ))->tm_wday, rec_id);
renatofilho@754
   542
    // _set_value (scheduler->msqlquery, "findtime",
renatofilho@754
   543
    // gmyth_util_time_to_string_only_time( schedule_info->start_time),
renatofilho@754
   544
    // rec_id);
renatofilho@754
   545
    // _set_int_value (scheduler->msqlquery, "findid",
renatofilho@754
   546
    // (gint)(schedule_info->start_time->tv_sec/60/60/24 + 719528),
renatofilho@754
   547
    // rec_id);
melunko@801
   548
renatofilho@890
   549
    if (schedule_info->seriesid)
renatofilho@890
   550
       _set_value(scheduler->msqlquery, "seriesid",
renatofilho@890
   551
                  schedule_info->seriesid->str, rec_id);
renatofilho@890
   552
 
renatofilho@754
   553
    _set_value(scheduler->msqlquery, "parentid", "0", rec_id);
renatofilho@754
   554
    _set_value(scheduler->msqlquery, "search", "0", rec_id);
melunko@801
   555
melunko@801
   556
    if (type == GMYTH_SCHEDULE_ALL_OCCURRENCES) {
morphbr@841
   557
        _set_int_value(scheduler->msqlquery, "type", 3, rec_id);
melunko@814
   558
    } else if (type == GMYTH_SCHEDULE_ONE_OCCURRENCE) {
melunko@814
   559
        _set_int_value(scheduler->msqlquery, "type", 1, rec_id);
melunko@814
   560
    } else if (type == GMYTH_SCHEDULE_EXCEPTION) {
melunko@814
   561
        _set_int_value(scheduler->msqlquery, "type", 8, rec_id);
melunko@836
   562
        _set_int_value(scheduler->msqlquery, "parentid", schedule_info->parentid,
melunko@814
   563
		       rec_id);
melunko@801
   564
    }
melunko@801
   565
renatofilho@754
   566
    _set_value(scheduler->msqlquery, "recpriority", "0", rec_id);
renatofilho@754
   567
    _set_value(scheduler->msqlquery, "startoffset", "0", rec_id);
renatofilho@754
   568
    _set_value(scheduler->msqlquery, "endoffset", "0", rec_id);
renatofilho@754
   569
    _set_value(scheduler->msqlquery, "dupmethod", "6", rec_id); // ?
renatofilho@754
   570
    _set_value(scheduler->msqlquery, "dupin", "15", rec_id);    // ?
melunko@567
   571
renatofilho@754
   572
    _set_value(scheduler->msqlquery, "prefinput", "0", rec_id);
renatofilho@754
   573
    _set_value(scheduler->msqlquery, "inactive", "0", rec_id);
renatofilho@754
   574
    _set_value(scheduler->msqlquery, "profile", "Default", rec_id);
renatofilho@754
   575
    _set_value(scheduler->msqlquery, "recgroup", "Default", rec_id);
renatofilho@754
   576
    _set_value(scheduler->msqlquery, "storagegroup", "Default", rec_id);
renatofilho@754
   577
    _set_value(scheduler->msqlquery, "playgroup", "Default", rec_id);
renatofilho@754
   578
    _set_value(scheduler->msqlquery, "autoexpire", "1", rec_id);
renatofilho@754
   579
    _set_value(scheduler->msqlquery, "maxepisodes", "0", rec_id);
renatofilho@754
   580
    _set_value(scheduler->msqlquery, "maxnewest", "0", rec_id);
renatofilho@754
   581
    _set_value(scheduler->msqlquery, "autocommflag", "1", rec_id);
renatofilho@754
   582
    _set_value(scheduler->msqlquery, "autotranscode", "0", rec_id);
renatofilho@754
   583
    _set_value(scheduler->msqlquery, "transcoder", "0", rec_id);
melunko@567
   584
renatofilho@754
   585
    _set_value(scheduler->msqlquery, "autouserjob1", "0", rec_id);
renatofilho@754
   586
    _set_value(scheduler->msqlquery, "autouserjob2", "0", rec_id);
renatofilho@754
   587
    _set_value(scheduler->msqlquery, "autouserjob3", "0", rec_id);
renatofilho@754
   588
    _set_value(scheduler->msqlquery, "autouserjob4", "0", rec_id);
melunko@567
   589
renatofilho@754
   590
    schedule_info->schedule_id = rec_id;
melunko@581
   591
melunko@836
   592
    /* Notify the backend of changes */
renatofilho@754
   593
    return update_backend(scheduler, rec_id);
leo_sobral@1
   594
}
leo_sobral@1
   595
melunko@801
   596
/** Requests the Mysql database in the backend to add a new schedule.
melunko@801
   597
 * 
melunko@801
   598
 * @param scheduler the GMythScheduler instance.
melunko@801
   599
 * @param schedule_info the ScheduleInfo with recording schedule information
melunko@801
   600
 * to be added. record_id = -1 to add a new schedule, otherwise this
melunko@801
   601
 * function will update the schedule in the db
melunko@801
   602
 * @return gboolean returns FALSE if some error occurs, TRUE otherwise
melunko@801
   603
 */
melunko@801
   604
gboolean
melunko@801
   605
gmyth_scheduler_add_schedule (GMythScheduler * scheduler,
melunko@801
   606
                             ScheduleInfo * schedule_info)
melunko@801
   607
{
melunko@801
   608
    return gmyth_scheduler_add_schedule_full (scheduler, schedule_info, 
melunko@801
   609
                                              GMYTH_SCHEDULE_ONE_OCCURRENCE);
melunko@801
   610
}
melunko@801
   611
leo_sobral@1
   612
/** Requests the Mysql database in the backend to remove an existing schedule.
leo_sobral@1
   613
 * 
leo_sobral@1
   614
 * @param scheduler the GMythScheduler instance.
melunko@814
   615
 * @param schedule_id The schedule's record id to be removed
leo_sobral@1
   616
 * @return gboolean TRUE if success, FALSE if error
leo_sobral@1
   617
 */
leo_sobral@1
   618
gboolean
melunko@814
   619
gmyth_scheduler_delete_schedule(GMythScheduler * scheduler, gint schedule_id)
leo_sobral@1
   620
{
leo_sobral@1
   621
renatofilho@754
   622
    MYSQL_RES      *msql_res;
melunko@814
   623
    GString        *query_str = NULL;
leo_sobral@1
   624
melunko@814
   625
    g_return_val_if_fail (scheduler != NULL, FALSE);
melunko@814
   626
rosfran@698
   627
renatofilho@754
   628
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   629
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   630
                  __FUNCTION__);
renatofilho@754
   631
        return FALSE;
renatofilho@754
   632
    }
melunko@814
   633
melunko@814
   634
    query_str = g_string_new("");
renatofilho@754
   635
    g_string_printf(query_str,
melunko@814
   636
                    "DELETE FROM record WHERE recordid=%d", schedule_id);
leo_sobral@1
   637
renatofilho@754
   638
    msql_res =
renatofilho@754
   639
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@754
   640
                                      query_str->str);
leo_sobral@1
   641
leo_sobral@1
   642
renatofilho@754
   643
    mysql_free_result(msql_res);
renatofilho@754
   644
    g_string_free(query_str, TRUE);
rosfran@698
   645
renatofilho@754
   646
    // Notify the backend of the changes
melunko@814
   647
    return update_backend(scheduler, schedule_id);
melunko@814
   648
}
melunko@814
   649
melunko@814
   650
/*
melunko@814
   651
 * Add an exception program to be removed from the schedule list, when programs
melunko@814
   652
 * where scheduled with the GMYTH_SCHEDULE_ALL_OCCURRENCES option.
melunko@814
   653
 * @param scheduler the GMythScheduler instance.
melunko@814
   654
 * @param schedule_id the schedule id of the all occurrence schedule to be changed
melunko@814
   655
 * @param exception_info the ScheduleInfo to be removed from all schedule occurrences
melunko@814
   656
 * @return TRUE if success, FALSE if any error happens
melunko@814
   657
 */
melunko@814
   658
gboolean
melunko@814
   659
gmyth_scheduler_add_exception (GMythScheduler *scheduler, gint schedule_id,
melunko@814
   660
			       ScheduleInfo *exception_info)
melunko@814
   661
{
melunko@814
   662
    gboolean res;
melunko@814
   663
melunko@814
   664
    g_return_val_if_fail (scheduler != NULL, FALSE);
melunko@814
   665
    g_return_val_if_fail (exception_info != NULL, FALSE);
melunko@814
   666
melunko@814
   667
    exception_info->parentid = schedule_id;
melunko@814
   668
    res = gmyth_scheduler_add_schedule_full (scheduler, exception_info, GMYTH_SCHEDULE_EXCEPTION);
melunko@814
   669
melunko@814
   670
    return res;
leo_sobral@1
   671
}
leo_sobral@1
   672
leo_sobral@1
   673
/** Requests the Mysql database in the backend to remove an existing recorded item.
leo_sobral@1
   674
 * 
leo_sobral@1
   675
 * @param scheduler the GMythScheduler instance.
leo_sobral@1
   676
 * @param record_id The recorded item id to be removed
leo_sobral@1
   677
 * @return gboolean TRUE if success, FALSE if error
leo_sobral@1
   678
 */
leo_sobral@1
   679
gboolean
renatofilho@750
   680
gmyth_scheduler_delete_recorded(GMythScheduler * scheduler, gint record_id)
leo_sobral@1
   681
{
leo_sobral@1
   682
renatofilho@754
   683
    MYSQL_RES      *msql_res;
melunko@117
   684
renatofilho@754
   685
    GString        *query_str = g_string_new("");
leo_sobral@1
   686
renatofilho@754
   687
    assert(scheduler);
rosfran@698
   688
renatofilho@754
   689
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   690
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   691
                  __FUNCTION__);
renatofilho@754
   692
        return FALSE;
renatofilho@754
   693
    }
renatofilho@754
   694
    // ========================================
renatofilho@754
   695
    g_string_printf(query_str,
renatofilho@754
   696
                    "DELETE FROM recorded WHERE recordid=%d", record_id);
leo_sobral@1
   697
renatofilho@754
   698
    // FIXME: Mythtv implementation runs also: DELETE FROM oldfind WHERE
renatofilho@754
   699
    // recordid = x
melunko@526
   700
renatofilho@754
   701
    msql_res =
renatofilho@754
   702
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@754
   703
                                      query_str->str);
rosfran@698
   704
renatofilho@754
   705
    mysql_free_result(msql_res);
renatofilho@754
   706
    g_string_free(query_str, TRUE);
rosfran@698
   707
renatofilho@754
   708
    // Notify the backend of the changes
renatofilho@754
   709
    return update_backend(scheduler, record_id);
leo_sobral@1
   710
}
leo_sobral@1
   711
morphbr@841
   712
morphbr@841
   713
gboolean gmyth_scheduler_was_recorded_before(GMythScheduler* scheduler, gint channel_id,
morphbr@841
   714
                                             time_t start_time)
morphbr@841
   715
{
morphbr@841
   716
    MYSQL_RES      *msql_res;
morphbr@841
   717
    GString        *query_str = g_string_new("");
morphbr@841
   718
morphbr@841
   719
    assert(scheduler);
morphbr@841
   720
    g_string_printf(query_str, "SELECT callsign FROM channel "
morphbr@841
   721
                    "WHERE chanid = \"%d\"", channel_id);
morphbr@841
   722
morphbr@841
   723
    msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
morphbr@841
   724
morphbr@841
   725
    if (msql_res) {
morphbr@841
   726
        MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
morphbr@841
   727
        if (msql_row) {
morphbr@841
   728
            GString* callsign = g_string_new(msql_row[0]);
morphbr@841
   729
            GString* startts = gmyth_util_time_to_string(start_time);
morphbr@841
   730
            g_string_printf(query_str, "SELECT * FROM oldrecorded "
morphbr@841
   731
                            "WHERE station = \"%s\" AND starttime = \"%s\"",
morphbr@841
   732
                            callsign->str, startts->str);
morphbr@841
   733
            msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
morphbr@841
   734
            g_string_free(callsign, TRUE);
morphbr@841
   735
            g_string_free(startts, TRUE);
morphbr@841
   736
            g_string_free(query_str, TRUE);
morphbr@841
   737
            if (mysql_fetch_row(msql_res)) return TRUE;
morphbr@841
   738
        }
morphbr@841
   739
    }
morphbr@841
   740
    return FALSE;
morphbr@841
   741
}
morphbr@841
   742
morphbr@841
   743
morphbr@841
   744
gboolean gmyth_scheduler_reactivate_schedule(GMythScheduler* scheduler, gint channel_id,
morphbr@841
   745
                                             time_t start_time)
morphbr@841
   746
morphbr@841
   747
{
morphbr@841
   748
    MYSQL_RES      *msql_res;
morphbr@841
   749
    GString        *query_str = g_string_new("");
morphbr@841
   750
morphbr@841
   751
    assert(scheduler);
morphbr@841
   752
    g_string_printf(query_str, "SELECT callsign FROM channel "
morphbr@841
   753
                    "WHERE chanid = \"%d\"", channel_id);
morphbr@841
   754
morphbr@841
   755
    msql_res = gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
morphbr@841
   756
    if (msql_res) {
morphbr@841
   757
        MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
morphbr@841
   758
        if (msql_row) {
morphbr@841
   759
            GString* callsign = g_string_new(msql_row[0]);
morphbr@841
   760
            GString* startts = gmyth_util_time_to_string(start_time);
morphbr@841
   761
            g_string_printf(query_str, "UPDATE oldrecorded SET reactivate = 1 "
morphbr@841
   762
                            "WHERE station = \"%s\" AND starttime = \"%s\"",
morphbr@841
   763
                            callsign->str, startts->str);
morphbr@841
   764
            gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
morphbr@841
   765
            g_string_free(callsign, TRUE);
morphbr@841
   766
            g_string_free(startts, TRUE);
morphbr@841
   767
            g_string_free(query_str, TRUE);
morphbr@841
   768
            return TRUE;
morphbr@841
   769
        }
morphbr@841
   770
morphbr@841
   771
    }
morphbr@841
   772
morphbr@841
   773
    return FALSE;
morphbr@841
   774
}
morphbr@841
   775
morphbr@841
   776
morphbr@841
   777
/*
morphbr@841
   778
 * This should only be used in special situations. We do not know the time that
morphbr@841
   779
 * the recording was set. We just know that it is an "ongoing" record and then
morphbr@841
   780
 * we have to use this to get it's info. It's always the oldest one -> first on list
morphbr@841
   781
 *
morphbr@841
   782
 */
morphbr@841
   783
GMythProgramInfo*
morphbr@841
   784
gmyth_scheduler_get_recorded_on_time(GMythScheduler* scheduler,
renatofilho@864
   785
                                     guint channel_id)
morphbr@841
   786
{
morphbr@841
   787
    MYSQL_RES      *msql_res;
morphbr@841
   788
    GMythProgramInfo *proginfo = NULL;
morphbr@841
   789
    GString        *query_str = g_string_new("");
morphbr@841
   790
morphbr@841
   791
    assert(scheduler);
morphbr@841
   792
morphbr@841
   793
    g_string_printf(query_str,
morphbr@841
   794
                    "SELECT recorded.chanid,starttime,endtime,title,"
morphbr@841
   795
                    "subtitle,description,channel.channum,"
morphbr@841
   796
                    "channel.callsign,channel.name,channel.commfree,"
morphbr@841
   797
                    "channel.outputfilters,seriesid,programid,filesize,"
morphbr@841
   798
                    "lastmodified,stars,previouslyshown,originalairdate,"
morphbr@841
   799
                    "hostname,recordid,transcoder,playgroup,"
morphbr@841
   800
                    "recorded.recpriority,progstart,progend,basename,recgroup,"
morphbr@841
   801
                    "category,findid,duplicate "
morphbr@841
   802
                    "FROM recorded " "LEFT JOIN channel "
morphbr@841
   803
                    "ON recorded.chanid = channel.chanid "
renatofilho@864
   804
                    "WHERE recorded.chanid = %d "
renatofilho@864
   805
                    "ORDER BY starttime DESC", channel_id);
morphbr@841
   806
morphbr@841
   807
    msql_res =
morphbr@841
   808
        gmyth_query_process_statement(scheduler->msqlquery, query_str->str);
morphbr@841
   809
morphbr@841
   810
    if (msql_res) {
morphbr@841
   811
        MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
morphbr@841
   812
morphbr@841
   813
        if (msql_row) {
morphbr@841
   814
            proginfo = gmyth_program_info_new();
morphbr@841
   815
renatofilho@895
   816
            proginfo->channel_id = (gint) g_ascii_strtoull (msql_row[0], NULL, 10);
morphbr@841
   817
            proginfo->recstartts = gmyth_util_string_to_time_val(msql_row[1]);
morphbr@841
   818
            proginfo->recendts = gmyth_util_string_to_time_val(msql_row[2]);
morphbr@841
   819
morphbr@841
   820
            proginfo->title = g_string_new(msql_row[3]);
morphbr@841
   821
            proginfo->subtitle = g_string_new(msql_row[4]);
morphbr@841
   822
            proginfo->description = g_string_new(msql_row[5]);
morphbr@841
   823
morphbr@841
   824
            proginfo->chanstr = g_string_new(msql_row[6]);
morphbr@841
   825
            proginfo->chansign = g_string_new(msql_row[7]);
morphbr@841
   826
            proginfo->channame = g_string_new(msql_row[8]);
morphbr@841
   827
            proginfo->chancommfree = (gint) g_ascii_strtoull(msql_row[9], NULL, 10);
morphbr@841
   828
            proginfo->chanOutputFilters = g_string_new(msql_row[10]);
morphbr@841
   829
            proginfo->seriesid = g_string_new(msql_row[11]);
renatofilho@895
   830
            proginfo->program_id = g_string_new(msql_row[12]);
morphbr@841
   831
            proginfo->filesize = g_ascii_strtoull(msql_row[13], NULL, 10);
morphbr@841
   832
morphbr@841
   833
            proginfo->lastmodified = gmyth_util_string_to_time_val(msql_row[14]);
morphbr@841
   834
            proginfo->stars = g_ascii_strtod(msql_row[15], NULL);
morphbr@841
   835
            proginfo->repeat = (gint)g_ascii_strtoull(msql_row[16], NULL, 10);
morphbr@841
   836
morphbr@841
   837
            if (msql_row[17] == NULL) {
morphbr@841
   838
                proginfo->originalAirDate = 0;
morphbr@841
   839
                proginfo->hasAirDate = FALSE;
morphbr@841
   840
            } else {
morphbr@841
   841
                proginfo->originalAirDate = gmyth_util_string_to_time_val(msql_row[17]);
morphbr@841
   842
                proginfo->hasAirDate = TRUE;
morphbr@841
   843
            }
morphbr@841
   844
morphbr@841
   845
            proginfo->hostname = g_string_new(msql_row[18]);
morphbr@841
   846
            proginfo->recordid = (gint) g_ascii_strtoull(msql_row[19], NULL, 10);
morphbr@841
   847
            proginfo->transcoder = (gint) g_ascii_strtoull(msql_row[20], NULL, 10);
morphbr@841
   848
morphbr@841
   849
            proginfo->playgroup = g_string_new(msql_row[21]);
morphbr@841
   850
            proginfo->recpriority = (gint) g_ascii_strtoull(msql_row[22], NULL, 10);
morphbr@841
   851
morphbr@841
   852
            proginfo->startts = gmyth_util_string_to_time_val(msql_row[23]);
morphbr@841
   853
            proginfo->endts = gmyth_util_string_to_time_val(msql_row[24]);
morphbr@841
   854
            proginfo->pathname = g_string_new(g_strdup(msql_row[25]));
morphbr@841
   855
            proginfo->recgroup = g_string_new(msql_row[26]);
morphbr@841
   856
            proginfo->category = g_string_new(msql_row[27]);
morphbr@841
   857
            proginfo->findid = (gint) g_ascii_strtoull(msql_row[28], NULL, 10);
morphbr@841
   858
morphbr@841
   859
            proginfo->recpriority2 = 0;
morphbr@841
   860
morphbr@841
   861
            g_string_printf(query_str,
morphbr@841
   862
                            "SELECT dupmethod,dupin,parentid,type "
morphbr@841
   863
                            "FROM record WHERE recordid = \"%d\"", proginfo->recordid);
morphbr@841
   864
morphbr@841
   865
            msql_res =
morphbr@841
   866
                gmyth_query_process_statement(scheduler->msqlquery,
morphbr@841
   867
                                              query_str->str);
morphbr@841
   868
morphbr@841
   869
            if (msql_res) {
morphbr@841
   870
                MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
morphbr@841
   871
morphbr@841
   872
                if (msql_row) {
morphbr@841
   873
                    proginfo->dupmethod = (gint) g_ascii_strtoull(msql_row[0], NULL, 10);
morphbr@841
   874
                    proginfo->dupin = (gint) g_ascii_strtoull(msql_row[1], NULL, 10);
morphbr@841
   875
                    proginfo->parentid = (gint) g_ascii_strtoull(msql_row[2], NULL, 10);
morphbr@841
   876
                    proginfo->rectype = 0;
morphbr@841
   877
                }
morphbr@841
   878
            }
morphbr@841
   879
morphbr@841
   880
morphbr@841
   881
            g_string_printf(query_str,
morphbr@841
   882
                            "SELECT sourceid,cardid,cardinputid,shareable "
morphbr@841
   883
                            "FROM cardinput");
morphbr@841
   884
morphbr@841
   885
            msql_res =
morphbr@841
   886
                gmyth_query_process_statement(scheduler->msqlquery,
morphbr@841
   887
                                              query_str->str);
morphbr@841
   888
morphbr@841
   889
            if (msql_res) {
morphbr@841
   890
                MYSQL_ROW msql_row = mysql_fetch_row(msql_res);
morphbr@841
   891
morphbr@841
   892
                if (msql_row) {
morphbr@841
   893
                    proginfo->sourceid = 0;
morphbr@841
   894
                    proginfo->cardid = 0;
morphbr@841
   895
                    proginfo->inputid = 0;
morphbr@841
   896
                    if (msql_row[3] != NULL && g_ascii_strcasecmp("Y", msql_row[3]) == 0)
morphbr@841
   897
                        proginfo->shareable = 1;
morphbr@841
   898
                    else
morphbr@841
   899
                        proginfo->shareable = 0;
morphbr@841
   900
                }
morphbr@841
   901
            }
morphbr@841
   902
morphbr@841
   903
morphbr@841
   904
morphbr@841
   905
        }
morphbr@841
   906
    }
morphbr@841
   907
morphbr@841
   908
    g_string_free(query_str, TRUE);
morphbr@841
   909
    return proginfo;
morphbr@841
   910
}
morphbr@841
   911
leo_sobral@1
   912
/** Retrieves an existing recorded item information from database. The information
leo_sobral@1
   913
 * is used to fill the returned GMythProgramInfo.
leo_sobral@1
   914
 * 
leo_sobral@1
   915
 * @param scheduler The GMythScheduler instance.
leo_sobral@1
   916
 * @param channel The channel associated to the record
leo_sobral@1
   917
 * @param starttime The record start time
leo_sobral@1
   918
 * @return A GMythProgramInfo struct with the requested record item
leo_sobral@1
   919
 * information, or NULL if error.
leo_sobral@1
   920
 */
rosfran@698
   921
GMythProgramInfo *
renatofilho@750
   922
gmyth_scheduler_get_recorded(GMythScheduler * scheduler,
renatofilho@754
   923
                             GString * channel, GTimeVal * starttime)
leo_sobral@1
   924
{
renatofilho@754
   925
    MYSQL_RES      *msql_res;
renatofilho@754
   926
    GMythProgramInfo *proginfo = NULL;
renatofilho@754
   927
    GString        *query_str = g_string_new("");
renatofilho@754
   928
    gchar          *time_str =
renatofilho@754
   929
        gmyth_util_time_to_string_from_time_val(starttime);
leo_sobral@1
   930
renatofilho@754
   931
    assert(scheduler);
melunko@412
   932
renatofilho@754
   933
    gmyth_debug("[%s] channel: %s", __FUNCTION__, channel->str);
rosfran@698
   934
renatofilho@754
   935
    if (scheduler->msqlquery == NULL) {
renatofilho@754
   936
        g_warning("[%s] Scheduler db connection not initialized",
renatofilho@754
   937
                  __FUNCTION__);
renatofilho@754
   938
        return NULL;
renatofilho@754
   939
    }
leo_sobral@1
   940
renatofilho@754
   941
    g_string_printf(query_str,
renatofilho@754
   942
                    "SELECT recorded.chanid,starttime,endtime,title, "
renatofilho@754
   943
                    "subtitle,description,channel.channum, "
renatofilho@754
   944
                    "channel.callsign,channel.name,channel.commfree, "
renatofilho@754
   945
                    "channel.outputfilters,seriesid,programid,filesize, "
renatofilho@754
   946
                    "lastmodified,stars,previouslyshown,originalairdate, "
renatofilho@754
   947
                    "hostname,recordid,transcoder,playgroup, "
renatofilho@754
   948
                    "recorded.recpriority,progstart,progend,basename,recgroup "
renatofilho@754
   949
                    "FROM recorded " "LEFT JOIN channel "
renatofilho@754
   950
                    "ON recorded.chanid = channel.chanid "
renatofilho@754
   951
                    "WHERE recorded.chanid = \"%s\" "
renatofilho@754
   952
                    "AND starttime = \"%s\" ;", channel->str, time_str);
leo_sobral@1
   953
renatofilho@754
   954
    msql_res =
renatofilho@754
   955
        gmyth_query_process_statement(scheduler->msqlquery,
renatofilho@754
   956
                                      query_str->str);
leo_sobral@1
   957
renatofilho@754
   958
    if (msql_res /* && query.size() > 0 */ ) {
renatofilho@754
   959
        MYSQL_ROW       msql_row = mysql_fetch_row(msql_res);
rosfran@698
   960
renatofilho@754
   961
        if (msql_row) {
renatofilho@754
   962
            proginfo = gmyth_program_info_new();
leo_sobral@1
   963
renatofilho@895
   964
            proginfo->channel_id = (gint) g_ascii_strtoull (msql_row[0], NULL, 10);
renatofilho@754
   965
            proginfo->startts =
renatofilho@754
   966
                gmyth_util_string_to_time_val(msql_row[23]);
renatofilho@754
   967
            proginfo->endts = gmyth_util_string_to_time_val(msql_row[24]);
renatofilho@754
   968
            proginfo->recstartts =
renatofilho@754
   969
                gmyth_util_string_to_time_val(msql_row[1]);
renatofilho@754
   970
            proginfo->recendts =
renatofilho@754
   971
                gmyth_util_string_to_time_val(msql_row[2]);
renatofilho@754
   972
            proginfo->title = g_string_new(msql_row[3]);
renatofilho@754
   973
            proginfo->subtitle = g_string_new(msql_row[4]);
renatofilho@754
   974
            proginfo->description = g_string_new(msql_row[5]);
leo_sobral@390
   975
renatofilho@754
   976
            proginfo->chanstr = g_string_new(msql_row[6]);
renatofilho@754
   977
            proginfo->chansign = g_string_new(msql_row[7]);
renatofilho@754
   978
            proginfo->channame = g_string_new(msql_row[0]);
renatofilho@754
   979
            proginfo->chancommfree =
renatofilho@754
   980
                (gint) g_ascii_strtoull(msql_row[9], NULL, 10);
renatofilho@754
   981
            proginfo->chanOutputFilters = g_string_new(msql_row[10]);
renatofilho@754
   982
            proginfo->seriesid = g_string_new(msql_row[11]);
renatofilho@895
   983
            proginfo->program_id = g_string_new(msql_row[12]);
renatofilho@754
   984
            proginfo->filesize = g_ascii_strtoull(msql_row[13], NULL, 10);
leo_sobral@1
   985
renatofilho@754
   986
            proginfo->lastmodified =
renatofilho@754
   987
                gmyth_util_string_to_time_val(msql_row[14]);
renatofilho@754
   988
            proginfo->stars = g_ascii_strtod(msql_row[15], NULL);
renatofilho@754
   989
            proginfo->repeat =
renatofilho@754
   990
                (gint) g_ascii_strtoull(msql_row[16], NULL, 10);
leo_sobral@390
   991
renatofilho@754
   992
            if (msql_row[17] == NULL) {
renatofilho@754
   993
                proginfo->originalAirDate = 0;
renatofilho@754
   994
                proginfo->hasAirDate = FALSE;
renatofilho@754
   995
            } else {
renatofilho@754
   996
                proginfo->originalAirDate =
renatofilho@754
   997
                    gmyth_util_string_to_time_val(msql_row[17]);
renatofilho@754
   998
                proginfo->hasAirDate = TRUE;
renatofilho@754
   999
            }
leo_sobral@390
  1000
renatofilho@754
  1001
            proginfo->hostname = g_string_new(msql_row[18]);
renatofilho@754
  1002
            proginfo->recordid =
renatofilho@754
  1003
                (gint) g_ascii_strtoull(msql_row[19], NULL, 10);
renatofilho@754
  1004
            proginfo->transcoder =
renatofilho@754
  1005
                (gint) g_ascii_strtoull(msql_row[20], NULL, 10);
renatofilho@754
  1006
            // proginfo->spread = -1;
renatofilho@754
  1007
            // proginfo->programflags = proginfo->getProgramFlags();
leo_sobral@391
  1008
renatofilho@754
  1009
            proginfo->recgroup = g_string_new(msql_row[26]);
renatofilho@754
  1010
            proginfo->playgroup = g_string_new(msql_row[21]);
renatofilho@754
  1011
            proginfo->recpriority =
renatofilho@754
  1012
                (gint) g_ascii_strtoull(msql_row[22], NULL, 10);
leo_sobral@391
  1013
renatofilho@754
  1014
            proginfo->pathname = g_string_new(g_strdup(msql_row[25]));
leo_sobral@391
  1015
renatofilho@754
  1016
            gmyth_debug("One program info loaded from mysql database\n");
renatofilho@754
  1017
        }
renatofilho@754
  1018
    }
leo_sobral@1
  1019
renatofilho@754
  1020
    mysql_free_result(msql_res);
renatofilho@754
  1021
    g_string_free(query_str, TRUE);
renatofilho@754
  1022
    g_free(time_str);
leo_sobral@1
  1023
renatofilho@754
  1024
    return proginfo;
leo_sobral@1
  1025
}
leo_sobral@1
  1026
renatofilho@864
  1027
gboolean
renatofilho@864
  1028
gmyth_scheduler_stop_recording (GMythScheduler * scheduler,
renatofilho@865
  1029
                                gint channel_id)
renatofilho@864
  1030
{
renatofilho@864
  1031
    GMythProgramInfo *program;
renatofilho@864
  1032
    GMythSocket    *socket;
renatofilho@864
  1033
    gboolean        res = FALSE;
renatofilho@864
  1034
    GMythStringList *slist;
renatofilho@864
  1035
renatofilho@864
  1036
    socket = gmyth_backend_info_get_connected_socket (scheduler->backend_info);
renatofilho@864
  1037
    program = gmyth_scheduler_get_recorded_on_time (scheduler, channel_id);
renatofilho@864
  1038
renatofilho@864
  1039
    if (program) {
renatofilho@864
  1040
        slist = gmyth_string_list_new();
renatofilho@864
  1041
        gmyth_string_list_append_char_array(slist, "STOP_RECORDING");
renatofilho@864
  1042
renatofilho@864
  1043
        gmyth_string_list_append_string(slist, program->title);        /* 0 */
renatofilho@864
  1044
        gmyth_string_list_append_string(slist, program->subtitle);     /* 1 */
renatofilho@864
  1045
        gmyth_string_list_append_string(slist, program->description);  /* 2 */
renatofilho@864
  1046
        gmyth_string_list_append_string(slist, program->category);     /* 3 */
renatofilho@895
  1047
        gmyth_string_list_append_int(slist, program->channel_id);   /* 4 */
renatofilho@864
  1048
        gmyth_string_list_append_string(slist, program->chanstr);      /* 5 */
renatofilho@864
  1049
        gmyth_string_list_append_string(slist, program->chansign);     /* 6 */
renatofilho@864
  1050
        gmyth_string_list_append_string(slist, program->channame);     /* 7 */
renatofilho@864
  1051
        gmyth_string_list_append_string(slist, program->pathname);     /* 8 */
renatofilho@864
  1052
        gmyth_string_list_append_int64(slist, program->filesize);      /* 9 */
renatofilho@864
  1053
renatofilho@864
  1054
        if (program->startts)
renatofilho@864
  1055
            gmyth_string_list_append_int(slist, program->startts->tv_sec); /* 10 */
renatofilho@864
  1056
        else
renatofilho@864
  1057
            gmyth_string_list_append_int(slist, 0);
renatofilho@864
  1058
renatofilho@864
  1059
        if (program->endts)
renatofilho@864
  1060
            gmyth_string_list_append_int(slist, program->endts->tv_sec);   /* 11 */
renatofilho@864
  1061
        else
renatofilho@864
  1062
            gmyth_string_list_append_int(slist, 0);
renatofilho@864
  1063
renatofilho@864
  1064
        gmyth_string_list_append_int(slist, program->duplicate);   /* 12 */
renatofilho@864
  1065
        gmyth_string_list_append_int(slist, program->shareable);   /* 13 */
renatofilho@864
  1066
        gmyth_string_list_append_int(slist, program->findid);      /* 14 */
renatofilho@864
  1067
        gmyth_string_list_append_string(slist, program->hostname); /* 15 */
renatofilho@864
  1068
        gmyth_string_list_append_int(slist, program->sourceid);    /* 16 */
renatofilho@864
  1069
        gmyth_string_list_append_int(slist, program->cardid);      /* 17 */
renatofilho@864
  1070
        gmyth_string_list_append_int(slist, program->inputid);     /* 18 */
renatofilho@864
  1071
        gmyth_string_list_append_int(slist, program->recpriority); /* 19 */
renatofilho@864
  1072
renatofilho@864
  1073
        // recstatus == recording
renatofilho@864
  1074
        gmyth_string_list_append_int(slist, -3);                   /* 20 */
renatofilho@864
  1075
renatofilho@864
  1076
        gmyth_string_list_append_int(slist, program->recordid);    /* 21 */
renatofilho@864
  1077
        gmyth_string_list_append_int(slist, program->rectype);     /* 22 */
renatofilho@864
  1078
        gmyth_string_list_append_int(slist, program->dupin);       /* 23 */
renatofilho@864
  1079
        gmyth_string_list_append_int(slist, program->dupmethod);   /* 24 */
renatofilho@864
  1080
renatofilho@864
  1081
renatofilho@864
  1082
        //fixme
renatofilho@864
  1083
        program->recstartts->tv_sec -= (60*60);
renatofilho@864
  1084
renatofilho@864
  1085
        gmyth_string_list_append_int(slist, 
renatofilho@864
  1086
                                     program->recstartts != NULL ?
renatofilho@864
  1087
                                     program->recstartts->tv_sec : 0);   /* 26 */
renatofilho@864
  1088
renatofilho@864
  1089
        gmyth_string_list_append_int(slist, 
renatofilho@864
  1090
                                     program->recendts != NULL ?
renatofilho@864
  1091
                                     program->recendts->tv_sec : 0);    /* 27 */
renatofilho@864
  1092
renatofilho@864
  1093
        gmyth_string_list_append_int(slist, program->repeat);       /* 28 */
renatofilho@864
  1094
        gmyth_string_list_append_int(slist, program->programflags); /* 29 */
renatofilho@864
  1095
renatofilho@864
  1096
        gmyth_string_list_append_char_array(slist, 
renatofilho@864
  1097
                                            program->recgroup != NULL ?
renatofilho@864
  1098
                                            program->recgroup->str : "Default");  /* 30 */
renatofilho@864
  1099
renatofilho@864
  1100
        gmyth_string_list_append_int(slist, program->chancommfree);         /* 31 */
renatofilho@864
  1101
        gmyth_string_list_append_string(slist, program->chanOutputFilters); /* 32 */
renatofilho@864
  1102
        gmyth_string_list_append_string(slist, program->seriesid);          /* 33 */
renatofilho@895
  1103
        gmyth_string_list_append_string(slist, program->program_id);     /* 34 */
renatofilho@864
  1104
renatofilho@864
  1105
        gmyth_string_list_append_int(slist,
renatofilho@864
  1106
                                     program->lastmodified != NULL ?
renatofilho@864
  1107
                                     program->lastmodified->tv_sec : 0);   /* 35 */
renatofilho@864
  1108
renatofilho@864
  1109
        gmyth_string_list_append_float(slist, program->stars); /* 36 */
renatofilho@864
  1110
renatofilho@864
  1111
        gmyth_string_list_append_int(slist,
renatofilho@864
  1112
                                     program->originalAirDate != NULL ?
renatofilho@864
  1113
                                     program->originalAirDate->tv_sec : 0); /* 37 */
renatofilho@864
  1114
renatofilho@864
  1115
        gmyth_string_list_append_int(slist, program->hasAirDate);  /* 38 */
renatofilho@864
  1116
renatofilho@864
  1117
        gmyth_string_list_append_char_array(slist,
renatofilho@864
  1118
                                            program->playgroup != NULL ?
renatofilho@864
  1119
                                            program->playgroup->str : "Default");  /* 39 */
renatofilho@864
  1120
renatofilho@864
  1121
        gmyth_string_list_append_int(slist, program->recpriority2); /* 40 */
renatofilho@864
  1122
        gmyth_string_list_append_int(slist, program->recpriority2); /* 40 */
renatofilho@864
  1123
renatofilho@864
  1124
        gmyth_socket_sendreceive_stringlist(socket, slist);
renatofilho@864
  1125
        res = (gmyth_string_list_get_int(slist, 0) == 1);
renatofilho@864
  1126
renatofilho@864
  1127
        g_object_unref (program);
renatofilho@864
  1128
        g_object_unref (slist);
renatofilho@864
  1129
    }
renatofilho@864
  1130
renatofilho@864
  1131
    g_object_unref (socket);
renatofilho@864
  1132
    return res;
renatofilho@864
  1133
}
renatofilho@864
  1134
renatofilho@864
  1135
leo_sobral@1
  1136
/** Notifies the backend of an update in the db.
leo_sobral@1
  1137
 * 
leo_sobral@1
  1138
 * @param record_id the id of the modified recording.
leo_sobral@1
  1139
 */
renatofilho@769
  1140
// fixme: put void and discovery record_id inside
renatofilho@769
  1141
static gboolean
renatofilho@769
  1142
update_backend (GMythScheduler * scheduler, 
renatofilho@769
  1143
                gint record_id)  
leo_sobral@1
  1144
{
renatofilho@754
  1145
    GMythSocket    *socket;
renatofilho@754
  1146
    GMythStringList *strlist = gmyth_string_list_new();
renatofilho@754
  1147
    GString        *datastr = g_string_new("RESCHEDULE_RECORDINGS ");
renatofilho@754
  1148
    gboolean        ret = FALSE;
leo_sobral@1
  1149
renatofilho@754
  1150
    g_string_append_printf(datastr, "%d", record_id);
renatofilho@754
  1151
    gmyth_string_list_append_string(strlist, datastr);
leo_sobral@1
  1152
renatofilho@769
  1153
    socket = gmyth_backend_info_get_connected_socket (scheduler->backend_info);
renatofilho@769
  1154
    if (socket != NULL) { 
renatofilho@754
  1155
        ret = (gmyth_socket_sendreceive_stringlist(socket, strlist) > 0);
renatofilho@769
  1156
        g_object_unref (socket);
renatofilho@754
  1157
    } else {
renatofilho@754
  1158
        g_warning("[%s] Connection to backend failed!", __FUNCTION__);
renatofilho@754
  1159
    }
rosfran@698
  1160
renatofilho@754
  1161
    g_string_free(datastr, TRUE);
renatofilho@754
  1162
    g_object_unref(strlist);
renatofilho@754
  1163
    return ret;
leo_sobral@1
  1164
}
renatofilho@129
  1165
renatofilho@129
  1166
void
renatofilho@750
  1167
gmyth_scheduler_recorded_info_get_preview(RecordedInfo * info,
renatofilho@754
  1168
                                          GByteArray * data)
renatofilho@129
  1169
{
renatofilho@129
  1170
}
renatofilho@129
  1171
renatofilho@129
  1172
void
renatofilho@750
  1173
gmyth_recorded_info_free(RecordedInfo * info)
renatofilho@129
  1174
{
renatofilho@890
  1175
    g_return_if_fail (info != NULL);
renatofilho@890
  1176
renatofilho@895
  1177
    if (info->program_id)
renatofilho@895
  1178
        g_string_free (info->program_id, TRUE);
renatofilho@886
  1179
renatofilho@754
  1180
    if (info->title != NULL)
renatofilho@754
  1181
        g_string_free(info->title, TRUE);
renatofilho@129
  1182
renatofilho@754
  1183
    if (info->subtitle != NULL)
renatofilho@754
  1184
        g_string_free(info->subtitle, TRUE);
renatofilho@129
  1185
renatofilho@754
  1186
    if (info->description != NULL)
renatofilho@754
  1187
        g_string_free(info->description, TRUE);
renatofilho@129
  1188
renatofilho@754
  1189
    if (info->category != NULL)
renatofilho@754
  1190
        g_string_free(info->category, TRUE);
renatofilho@129
  1191
renatofilho@754
  1192
    if (info->basename != NULL)
renatofilho@754
  1193
        g_string_free(info->basename, TRUE);
renatofilho@129
  1194
renatofilho@754
  1195
    if (info != NULL)
renatofilho@754
  1196
        g_free(info->start_time);
leo_sobral@387
  1197
renatofilho@754
  1198
    if (info != NULL)
renatofilho@754
  1199
        g_free(info->end_time);
leo_sobral@387
  1200
renatofilho@754
  1201
    g_free(info);
renatofilho@129
  1202
}
renatofilho@129
  1203
melunko@591
  1204
static void
renatofilho@750
  1205
free_recorded_info_item(gpointer data, gpointer user_data)
melunko@591
  1206
{
renatofilho@754
  1207
    RecordedInfo   *info = (RecordedInfo *) data;
melunko@591
  1208
renatofilho@754
  1209
    gmyth_recorded_info_free(info);
melunko@591
  1210
}
melunko@591
  1211
renatofilho@129
  1212
void
renatofilho@750
  1213
gmyth_recorded_info_list_free(GList * list)
renatofilho@129
  1214
{
renatofilho@754
  1215
    g_return_if_fail(list != NULL);
melunko@591
  1216
renatofilho@754
  1217
    g_list_foreach(list, free_recorded_info_item, NULL);
renatofilho@754
  1218
    g_list_free(list);
melunko@591
  1219
}
melunko@591
  1220
melunko@591
  1221
void
renatofilho@750
  1222
gmyth_schedule_info_free(ScheduleInfo * info)
melunko@591
  1223
{
melunko@591
  1224
renatofilho@754
  1225
    g_return_if_fail(info != NULL);
melunko@591
  1226
renatofilho@895
  1227
    if (info->program_id)
renatofilho@895
  1228
        g_string_free (info->program_id, TRUE);
renatofilho@886
  1229
renatofilho@754
  1230
    if (info->title != NULL)
renatofilho@754
  1231
        g_string_free(info->title, TRUE);
renatofilho@129
  1232
renatofilho@754
  1233
    if (info->subtitle != NULL)
renatofilho@754
  1234
        g_string_free(info->subtitle, TRUE);
renatofilho@129
  1235
renatofilho@754
  1236
    if (info->description != NULL)
renatofilho@754
  1237
        g_string_free(info->description, TRUE);
renatofilho@129
  1238
renatofilho@754
  1239
    if (info->category != NULL)
renatofilho@754
  1240
        g_string_free(info->category, TRUE);
renatofilho@129
  1241
renatofilho@754
  1242
    if (info != NULL)
renatofilho@754
  1243
        g_free(info->start_time);
leo_sobral@387
  1244
renatofilho@754
  1245
    if (info != NULL)
renatofilho@754
  1246
        g_free(info->end_time);
leo_sobral@387
  1247
renatofilho@754
  1248
    g_free(info);
renatofilho@129
  1249
}
renatofilho@129
  1250
melunko@591
  1251
static void
renatofilho@750
  1252
free_schedule_info_item(gpointer data, gpointer user_data)
melunko@591
  1253
{
renatofilho@754
  1254
    ScheduleInfo   *info = (ScheduleInfo *) data;
melunko@591
  1255
renatofilho@754
  1256
    gmyth_schedule_info_free(info);
melunko@591
  1257
}
melunko@591
  1258
melunko@591
  1259
void
renatofilho@750
  1260
gmyth_schedule_info_list_free(GList * list)
melunko@591
  1261
{
renatofilho@754
  1262
    g_return_if_fail(list != NULL);
melunko@591
  1263
renatofilho@754
  1264
    g_list_foreach(list, free_schedule_info_item, NULL);
renatofilho@754
  1265
    g_list_free(list);
melunko@591
  1266
}