~ubuntu-branches/ubuntu/lucid/mythtv/lucid

« back to all changes in this revision

Viewing changes to libs/libmythtv/channelscan/channelimporter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2009-09-08 23:08:37 UTC
  • mfrom: (1.1.32 upstream)
  • Revision ID: james.westby@ubuntu.com-20090908230837-zrm2j6wutp76hwso
Tags: 0.22.0~trunk21742-0ubuntu1
* New upstream checkout (21742)
  - Fixes FTBFS on PPC. See changeset 21571 for more details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    {
33
33
        if (use_gui)
34
34
        {
 
35
            VERBOSE(VB_IMPORTANT, LOC + (ChannelUtil::GetChannelCount()
 
36
                                         ? "No new channels to process"
 
37
                                         : "No channels to process.."));
35
38
            MythPopupBox::showOkPopup(
36
39
                gContext->GetMainWindow(), QObject::tr("Channel Importer"),
37
40
                ChannelUtil::GetChannelCount()
40
43
        }
41
44
        else
42
45
        {
43
 
            VERBOSE(VB_IMPORTANT, LOC + (ChannelUtil::GetChannelCount()
44
 
                                         ? "No new channels to process"
45
 
                                         : "No channels to process.."));
 
46
            cout << (ChannelUtil::GetChannelCount() ?
 
47
                     "No new channels to process" :
 
48
                     "No channels to process..");
46
49
        }
47
50
 
48
51
        return;
74
77
    // Make sure "Open Cable" channels are marked that way.
75
78
    FixUpOpenCable(transports);
76
79
 
 
80
    // if scan was not aborted prematurely..
 
81
    uint deleted_count = 0;
 
82
    if (do_delete)
 
83
    {
 
84
        ScanDTVTransportList trans = transports;
 
85
        for (uint i = 0; i < db_trans.size(); i++)
 
86
            trans.push_back(db_trans[i]);
 
87
        deleted_count = DeleteChannels(trans);
 
88
        if (deleted_count)
 
89
            transports = trans;
 
90
    }
 
91
 
77
92
    // Determine System Info standards..
78
93
    ChannelImporterBasicStats info = CollectStats(transports);
79
94
 
88
103
    QString msg = GetSummary(transports.size(), info, stats);
89
104
    cout << msg.toAscii().constData() << endl << endl;
90
105
 
91
 
/*
92
 
    if (use_gui)
93
 
    {
94
 
        MythPopupBox::showOkPopup(
95
 
            gContext->GetMainWindow(), QObject::tr("Channel Importer"), msg);
96
 
    }
97
 
*/
98
 
 
99
106
    if (do_insert)
100
 
    {
101
107
        InsertChannels(transports, info);
 
108
 
 
109
    if (do_delete && sourceid)
 
110
        DeleteUnusedTransports(sourceid);
 
111
 
 
112
    if (do_delete || do_insert)
102
113
        ScanInfo::MarkProcessed(saved_scan);
103
 
    }
104
114
}
105
115
 
106
116
QString ChannelImporter::toString(ChannelType type)
123
133
    return "Unknown";
124
134
}
125
135
 
 
136
uint ChannelImporter::DeleteChannels(
 
137
    ScanDTVTransportList &transports)
 
138
{
 
139
    vector<uint> off_air_list;
 
140
    QMap<uint,bool> deleted;
 
141
 
 
142
    for (uint i = 0; i < transports.size(); i++)
 
143
    {
 
144
        for (uint j = 0; j < transports[i].channels.size(); j++)
 
145
        {
 
146
            ChannelInsertInfo chan = transports[i].channels[j];
 
147
            bool was_in_db = chan.db_mplexid && chan.channel_id;
 
148
            if (!was_in_db)
 
149
                continue;
 
150
 
 
151
            if (!chan.in_pmt)
 
152
                off_air_list.push_back(i<<16|j);
 
153
        }
 
154
    }
 
155
 
 
156
    ScanDTVTransportList newlist;
 
157
    if (off_air_list.empty())
 
158
    {
 
159
        return 0;
 
160
    }
 
161
 
 
162
    // ask user whether to delete all or some of these stale channels
 
163
    //   if some is selected ask about each individually
 
164
    QString msg = QObject::tr(
 
165
        "Found %1 off-air channels.").arg(off_air_list.size());
 
166
    DeleteAction action = QueryUserDelete(msg);
 
167
    if (kDeleteIgnoreAll == action)
 
168
        return 0;
 
169
 
 
170
    if (kDeleteAll == action)
 
171
    {
 
172
        for (uint k = 0; k < off_air_list.size(); k++)
 
173
        {
 
174
            int i = off_air_list[k] >> 16, j = off_air_list[k] & 0xFFFF;
 
175
            ChannelUtil::DeleteChannel(
 
176
                transports[i].channels[j].channel_id);
 
177
            deleted[off_air_list[k]] = true;
 
178
        }
 
179
    }
 
180
    else if (kDeleteInvisibleAll == action)
 
181
    {
 
182
        for (uint k = 0; k < off_air_list.size(); k++)
 
183
        {
 
184
            int i = off_air_list[k] >> 16, j = off_air_list[k] & 0xFFFF;
 
185
            ChannelUtil::SetVisible(
 
186
                transports[i].channels[j].channel_id, false);
 
187
        }
 
188
    }
 
189
    else
 
190
    {
 
191
        // TODO manual delete
 
192
    }
 
193
 
 
194
    // TODO delete encrypted channels when m_fta_only set
 
195
 
 
196
    if (deleted.size() == 0)
 
197
        return 0;
 
198
 
 
199
    // Create a new transports list without the deleted channels
 
200
    for (uint i = 0; i < transports.size(); i++)
 
201
    {
 
202
        newlist.push_back(transports[i]);
 
203
        newlist.back().channels.clear();
 
204
        for (uint j = 0; j < transports[i].channels.size(); j++)
 
205
        {
 
206
            if (!deleted.contains(i<<16|j))
 
207
            {
 
208
                newlist.back().channels.push_back(
 
209
                    transports[i].channels[j]);
 
210
            }
 
211
        }
 
212
    }
 
213
 
 
214
    // TODO print list of stale channels (as deleted if action approved).
 
215
 
 
216
    transports = newlist;
 
217
    return deleted.size();
 
218
}
 
219
 
 
220
uint ChannelImporter::DeleteUnusedTransports(uint sourceid)
 
221
{
 
222
    MSqlQuery query(MSqlQuery::InitCon());
 
223
    query.prepare(
 
224
        "SELECT mplexid FROM dtv_multiplex "
 
225
        "WHERE sourceid = :SOURCEID1 AND "
 
226
        "      mplexid NOT IN "
 
227
        " (SELECT mplexid "
 
228
        "  FROM channel "
 
229
        "  WHERE sourceid = :SOURCEID2)");
 
230
    query.bindValue(":SOURCEID1", sourceid);
 
231
    query.bindValue(":SOURCEID2", sourceid);
 
232
    if (!query.exec())
 
233
    {
 
234
        MythDB::DBError("DeleteUnusedTransports() -- select", query);
 
235
        return 0;
 
236
    }
 
237
 
 
238
    VERBOSE(VB_IMPORTANT, 
 
239
            QObject::tr("Found %1 unused transports.").arg(query.size()));
 
240
 
 
241
    if (query.size() == 0)
 
242
        return 0;
 
243
 
 
244
    QString msg = QObject::tr("Found %1 unused transports.").arg(query.size());
 
245
    DeleteAction action = QueryUserDelete(msg);
 
246
    if (kDeleteIgnoreAll == action)
 
247
        return 0;
 
248
 
 
249
    if (kDeleteAll == action)
 
250
    {
 
251
        query.prepare(
 
252
            "DELETE FROM dtv_multiplex "
 
253
            "WHERE sourceid = :SOURCEID1 AND "
 
254
            "      mplexid NOT IN "
 
255
            " (SELECT mplexid "
 
256
            "  FROM channel "
 
257
            "  WHERE sourceid = :SOURCEID2)");
 
258
        query.bindValue(":SOURCEID1", sourceid);
 
259
        query.bindValue(":SOURCEID2", sourceid);
 
260
        if (!query.exec())
 
261
        {
 
262
            MythDB::DBError("DeleteUnusedTransports() -- delete", query);
 
263
            return 0;
 
264
        }
 
265
    }
 
266
    else
 
267
    {
 
268
        // TODO manual delete
 
269
    }
 
270
    return 0;
 
271
}
 
272
 
126
273
void ChannelImporter::InsertChannels(
127
274
    const ScanDTVTransportList &transports,
128
275
    const ChannelImporterBasicStats &info)
205
352
        }
206
353
    }    
207
354
 
208
 
    // if scan was not aborted prematurely
209
 
    //   ask user whether to delete all or some of these stale channels
210
 
    //     if some is selected ask about each individually
211
 
    //   ask user whether to delete all or some of these stale transports
212
 
    //     if some is selected ask about each individually
213
 
 
214
355
    // print list of inserted channels
215
356
    // print list of ignored channels (by ignored reason category)
216
357
    // print list of invalid channels
217
 
    // print list of stale channels (as deleted if action approved).
218
358
}
219
359
 
220
360
ScanDTVTransportList ChannelImporter::InsertChannels(
574
714
 
575
715
void ChannelImporter::FilterServices(ScanDTVTransportList &transports) const
576
716
{
 
717
    bool require_av = (m_service_requirements & kRequireAV) == kRequireAV;
 
718
    bool require_a  = m_service_requirements & kRequireAudio;
 
719
        
577
720
    for (uint i = 0; i < transports.size(); i++)
578
721
    {
579
722
        ChannelInsertInfoList filtered;
583
726
                transports[i].channels[k].decryption_status != kEncDecrypted)
584
727
                continue;
585
728
 
586
 
            if (transports[i].channels[k].is_data_service)
 
729
            if (require_a && transports[i].channels[k].is_data_service)
587
730
                continue;
588
731
 
589
 
            if (!m_add_radio_services &&
590
 
                transports[i].channels[k].is_audio_service)
 
732
            if (require_av && transports[i].channels[k].is_audio_service)
591
733
                continue;
592
734
 
593
735
            // filter channels out only in channels.conf, i.e. not found
1012
1154
    return chan_num;
1013
1155
}
1014
1156
 
 
1157
ChannelImporter::DeleteAction
 
1158
ChannelImporter::QueryUserDelete(const QString &msg)
 
1159
{
 
1160
    DeleteAction action = kDeleteAll;
 
1161
    if (use_gui)
 
1162
    {
 
1163
        QStringList buttons;
 
1164
        buttons.push_back(QObject::tr("Delete all"));
 
1165
        buttons.push_back(QObject::tr("Set all invisible"));
 
1166
//        buttons.push_back(QObject::tr("Handle manually"));
 
1167
        buttons.push_back(QObject::tr("Ignore all"));
 
1168
 
 
1169
        DialogCode ret;
 
1170
        do
 
1171
        {
 
1172
            ret = MythPopupBox::ShowButtonPopup(
 
1173
                gContext->GetMainWindow(), QObject::tr("Channel Importer"),
 
1174
                msg, buttons, kDialogCodeButton0);
 
1175
 
 
1176
            ret = (kDialogCodeRejected == ret) ? kDialogCodeButton2 : ret;
 
1177
 
 
1178
        } while (!(kDialogCodeButton0 <= ret && ret <= kDialogCodeButton3));
 
1179
 
 
1180
        action = (kDialogCodeButton0 == ret) ? kDeleteAll       : action;
 
1181
        action = (kDialogCodeButton1 == ret) ? kDeleteInvisibleAll : action;
 
1182
        action = (kDialogCodeButton2 == ret) ? kDeleteIgnoreAll   : action;
 
1183
//        action = (kDialogCodeButton2 == ret) ? kDeleteManual    : action;
 
1184
//        action = (kDialogCodeButton3 == ret) ? kDeleteIgnoreAll : action;
 
1185
    }
 
1186
    else if (is_interactive)
 
1187
    {
 
1188
        cout << msg.toAscii().constData()          << endl;
 
1189
        cout << "Do you want to:"    << endl;
 
1190
        cout << "1. Delete all"      << endl;
 
1191
        cout << "2. Set all invisible" << endl;
 
1192
//        cout << "3. Handle manually" << endl;
 
1193
        cout << "4. Ignore all"      << endl;
 
1194
        while (true)
 
1195
        {
 
1196
            string ret;
 
1197
            cin >> ret;
 
1198
            bool ok;
 
1199
            uint val = QString(ret.c_str()).toUInt(&ok);
 
1200
            if (ok && (1 <= val) && (val <= 3))
 
1201
            {
 
1202
                action = (1 == val) ? kDeleteAll       : action;
 
1203
                action = (2 == val) ? kDeleteInvisibleAll : action;
 
1204
                //action = (3 == val) ? kDeleteManual    : action;
 
1205
                action = (3 == val) ? kDeleteIgnoreAll : action;
 
1206
                action = (4 == val) ? kDeleteIgnoreAll : action;
 
1207
                break;
 
1208
            }
 
1209
            else
 
1210
            {
 
1211
                //cout << "Please enter either 1, 2, 3 or 4:" << endl;
 
1212
                cout << "Please enter either 1, 2 or 4:" << endl;//
 
1213
            }
 
1214
        }
 
1215
    }
 
1216
 
 
1217
    return action;
 
1218
}
 
1219
 
1015
1220
ChannelImporter::InsertAction
1016
1221
ChannelImporter::QueryUserInsert(const QString &msg)
1017
1222
{