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

« back to all changes in this revision

Viewing changes to programs/mythfrontend/proglist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello, Mario Limonciello, John Baab
  • Date: 2009-09-29 01:33:23 UTC
  • mfrom: (1.1.35 upstream)
  • Revision ID: james.westby@ubuntu.com-20090929013323-6pvn8encm757zbxw
Tags: 0.22.0~trunk22101-0ubuntu1
[ Mario Limonciello ]
* New upstream checkout (r22101)
* Try to guard and make sure that ~mythtv is read from /etc/passwd 
  rather than assuming it's /home/mythtv.

[ John Baab ]
* debian/mythtv-common.postinst:
  - Added symlink for /home/mythtv/.mythtv/config.xml

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "proglist.h"
 
3
 
 
4
// C/C++
1
5
#include <iostream>
2
6
#include <map>
3
7
#include <vector>
8
12
#include <QApplication>
9
13
#include <QRegExp>
10
14
 
11
 
// MythTV
 
15
// libmyth
12
16
#include "mythcontext.h"
13
 
#include "proglist.h"
 
17
#include "remoteutil.h"
 
18
 
 
19
// libmythtv
14
20
#include "scheduledrecording.h"
15
21
#include "recordingrule.h"
16
 
#include "remoteutil.h"
17
22
#include "channelutil.h"
18
23
#include "recordinginfo.h"
 
24
 
 
25
// libmythdb
19
26
#include "mythdb.h"
20
27
#include "mythdbcon.h"
21
28
#include "mythverbose.h"
 
29
 
 
30
// libmythui
22
31
#include "mythuitext.h"
23
32
#include "mythuibutton.h"
24
33
#include "mythuibuttonlist.h"
39
48
 
40
49
    m_dayFormat = gContext->GetSetting("DateFormat");
41
50
    m_hourFormat = gContext->GetSetting("TimeFormat");
42
 
    m_fullDateFormat = m_dayFormat + " " + m_hourFormat;
 
51
    m_fullDateFormat = m_dayFormat + ' ' + m_hourFormat;
43
52
    m_channelOrdering = gContext->GetSetting("ChannelOrdering", "channum");
44
53
    m_channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>");
45
54
 
75
84
    m_recid = recid;
76
85
    m_title = title;
77
86
 
78
 
    m_addTables = "";
 
87
    m_addTables.clear();
79
88
    m_startTime = QDateTime::currentDateTime();
80
89
    m_searchTime = m_startTime;
81
90
 
82
91
    m_dayFormat = gContext->GetSetting("DateFormat");
83
92
    m_hourFormat = gContext->GetSetting("TimeFormat");
84
 
    m_timeFormat = gContext->GetSetting("ShortDateFormat") + " " + m_hourFormat;
85
 
    m_fullDateFormat = m_dayFormat + " " + m_hourFormat;
 
93
    m_timeFormat = gContext->GetSetting("ShortDateFormat") + ' ' + m_hourFormat;
 
94
    m_fullDateFormat = m_dayFormat + ' ' + m_hourFormat;
86
95
    m_channelOrdering = gContext->GetSetting("ChannelOrdering", "channum");
87
96
    m_channelFormat = gContext->GetSetting("ChannelFormat", "<num> <sign>");
88
97
 
189
198
    QStringList actions;
190
199
    handled = gContext->GetMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
191
200
 
192
 
    for (int i = 0; i < actions.size() && !handled; i++)
 
201
    for (int i = 0; i < actions.size() && !handled; ++i)
193
202
    {
194
203
        QString action = actions[i];
195
204
        handled = true;
368
377
    int oldview = m_viewList.indexOf(oldValue);
369
378
    int newview = m_viewList.indexOf(text);
370
379
 
371
 
    QString qphrase = NULL;
372
 
 
373
380
    if (newview < 0 || newview != oldview)
374
381
    {
 
382
        QString qphrase;
375
383
        if (oldview >= 0)
376
384
        {
377
385
            qphrase = m_viewList[oldview];
448
456
             m_type == plPeopleSearch)
449
457
    {
450
458
        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
451
 
        QString currentItem = "";
 
459
        QString currentItem;
452
460
 
453
461
        if (m_curView >= 0)
454
462
            currentItem = m_viewList[m_curView];
471
479
    else if (m_type == plPowerSearch)
472
480
    {
473
481
        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
474
 
        QString currentItem = "";
 
482
        QString currentItem;
475
483
 
476
484
        if (m_curView >= 0)
477
485
            currentItem = m_viewList[m_curView];
492
500
    else if (m_type == plTime)
493
501
    {
494
502
        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
495
 
        QString currentItem = "";
 
503
        QString currentItem;
496
504
 
497
505
        TimePopup *popup = new TimePopup(popupStack, this);
498
506
 
528
536
                                  MSqlBindings &bindings)
529
537
{
530
538
    int ret = 0;
531
 
    output = "";
 
539
    output.clear();
532
540
    QString curfield;
533
541
 
534
 
    QStringList field = qphrase.split(":");
 
542
    QStringList field = qphrase.split(':');
535
543
 
536
544
    if (field.count() != 6)
537
545
    {
542
550
 
543
551
    if (!field[0].isEmpty())
544
552
    {
545
 
        curfield = "%" + field[0] + "%";
 
553
        curfield = '%' + field[0] + '%';
546
554
        output += "program.title LIKE :POWERTITLE ";
547
555
        bindings[":POWERTITLE"] = curfield;
548
556
    }
549
557
 
550
558
    if (!field[1].isEmpty())
551
559
    {
552
 
        if (output > "")
 
560
        if (!output.isEmpty())
553
561
            output += "\nAND ";
554
562
 
555
 
        curfield = "%" + field[1] + "%";
 
563
        curfield = '%' + field[1] + '%';
556
564
        output += "program.subtitle LIKE :POWERSUB ";
557
565
        bindings[":POWERSUB"] = curfield;
558
566
    }
559
567
 
560
568
    if (!field[2].isEmpty())
561
569
    {
562
 
        if (output > "")
 
570
        if (!output.isEmpty())
563
571
            output += "\nAND ";
564
572
 
565
 
        curfield = "%" + field[2] + "%";
 
573
        curfield = '%' + field[2] + '%';
566
574
        output += "program.description LIKE :POWERDESC ";
567
575
        bindings[":POWERDESC"] = curfield;
568
576
    }
569
577
 
570
578
    if (!field[3].isEmpty())
571
579
    {
572
 
        if (output > "")
 
580
        if (!output.isEmpty())
573
581
            output += "\nAND ";
574
582
 
575
583
        output += "program.category_type = :POWERCATTYPE ";
578
586
 
579
587
    if (!field[4].isEmpty())
580
588
    {
581
 
        if (output > "")
 
589
        if (!output.isEmpty())
582
590
            output += "\nAND ";
583
591
 
584
592
        output += "programgenres.genre = :POWERGENRE ";
588
596
 
589
597
    if (!field[5].isEmpty())
590
598
    {
591
 
        if (output > "")
 
599
        if (!output.isEmpty())
592
600
            output += "\nAND ";
593
601
 
594
602
        output += "channel.callsign = :POWERCALLSIGN ";
626
634
{
627
635
    ProgramInfo *pi = m_itemList.at(m_progList->GetCurrentPos());
628
636
 
629
 
    if (!pi)
630
 
        return;
631
 
 
632
637
    EditScheduled(pi);
633
638
}
634
639
 
636
641
{
637
642
    ProgramInfo *pi = m_itemList.at(m_progList->GetCurrentPos());
638
643
 
639
 
    if (!pi)
640
 
        return;
641
 
 
642
 
    MythScreenStack *mainStack = GetMythMainWindow()->GetStack("popup stack");
643
 
    CustomEdit *ce = new CustomEdit(mainStack, pi);
644
 
    if (ce->Create())
645
 
        mainStack->AddScreen(ce);
646
 
    else
647
 
        delete ce;
 
644
    EditCustom(pi);
648
645
}
649
646
 
650
647
void ProgLister::deleteItem()
827
824
                                                       "channum, chanid");
828
825
        ChannelUtil::SortChannels(channels, m_channelOrdering, true);
829
826
 
830
 
        for (uint i = 0; i < channels.size(); i++)
 
827
        for (uint i = 0; i < channels.size(); ++i)
831
828
        {
832
829
            QString chantext = m_channelFormat;
833
830
            chantext
860
857
 
861
858
        if (query.exec() && query.size())
862
859
        {
863
 
            QString lastGenre1;
 
860
            QString lastGenre1, genre1;
864
861
 
865
862
            while (query.next())
866
863
            {
867
 
                QString genre1 = query.value(0).toString();
868
 
                if (genre1 <= " ")
 
864
                genre1 = query.value(0).toString();
 
865
                if (genre1.isEmpty())
869
866
                    continue;
870
867
 
871
868
                if (genre1 != lastGenre1)
876
873
                }
877
874
 
878
875
                QString genre2 = query.value(1).toString();
879
 
                if (genre2 <= " " || genre2 == genre1)
 
876
                if (genre2.isEmpty() || genre2 == genre1)
880
877
                    continue;
881
878
 
882
879
                m_viewList << genre1 + ":/:" + genre2;
893
890
                          "GROUP BY category;");
894
891
            query.bindValue(":PGILSTART", startstr);
895
892
 
896
 
            if (query.exec() && query.size())
 
893
            if (query.exec())
897
894
            {
898
895
                while (query.next())
899
896
                {
920
917
                      "WHERE searchtype = :SEARCHTYPE;");
921
918
        query.bindValue(":SEARCHTYPE", m_searchType);
922
919
 
923
 
        if (query.exec() && query.size())
 
920
        if (query.exec())
924
921
        {
925
922
            while (query.next())
926
923
            {
927
924
                QString phrase = query.value(0).toString();
928
 
                if (phrase <= " ")
 
925
                if (phrase.isEmpty())
929
926
                    continue;
930
927
                phrase = query.value(0).toString();
931
928
                m_viewList << phrase;
1201
1198
        m_curviewText->SetText(m_viewTextList[m_curView]);
1202
1199
 
1203
1200
    bool oneChanid = false;
1204
 
    QString where = "";
 
1201
    QString where;
1205
1202
    QString startstr = m_startTime.toString("yyyy-MM-ddThh:mm:50");
1206
1203
    QString qphrase = m_viewList[m_curView];
1207
1204
 
1260
1257
        where = "WHERE channel.visible = 1 "
1261
1258
                "  AND program.endtime > :PGILSTART "
1262
1259
                "  AND program.title LIKE :PGILLIKEPHRASE0 ";
1263
 
        bindings[":PGILLIKEPHRASE0"] = QString("%") + qphrase + "%";
 
1260
        bindings[":PGILLIKEPHRASE0"] = QString("%") + qphrase + '%';
1264
1261
    }
1265
1262
    else if (m_type == plKeywordSearch) // keyword search
1266
1263
    {
1269
1266
                "  AND (program.title LIKE :PGILLIKEPHRASE1 "
1270
1267
                "    OR program.subtitle LIKE :PGILLIKEPHRASE2 "
1271
1268
                "    OR program.description LIKE :PGILLIKEPHRASE3 ) ";
1272
 
        bindings[":PGILLIKEPHRASE1"] = QString("%") + qphrase + "%";
1273
 
        bindings[":PGILLIKEPHRASE2"] = QString("%") + qphrase + "%";
1274
 
        bindings[":PGILLIKEPHRASE3"] = QString("%") + qphrase + "%";
 
1269
        bindings[":PGILLIKEPHRASE1"] = QString("%") + qphrase + '%';
 
1270
        bindings[":PGILLIKEPHRASE2"] = QString("%") + qphrase + '%';
 
1271
        bindings[":PGILLIKEPHRASE3"] = QString("%") + qphrase + '%';
1275
1272
    }
1276
1273
    else if (m_type == plPeopleSearch) // people search
1277
1274
    {
1309
1306
        where = QString("WHERE channel.visible = 1 "
1310
1307
                        "  AND program.endtime > :PGILSTART "
1311
1308
                        "  AND ( %1 ) ").arg(qphrase);
1312
 
        if (m_addTables > "")
1313
 
            where = m_addTables + " " + where;
 
1309
        if (!m_addTables.isEmpty())
 
1310
            where = m_addTables + ' ' + where;
1314
1311
    }
1315
1312
    else if (m_type == plChannel) // list by channel
1316
1313
    {
1360
1357
        where = "WHERE channel.visible = 1 "
1361
1358
                "  AND program.endtime > :PGILSTART "
1362
1359
                "  AND program.category_type = 'movie' "
1363
 
                "  AND program.stars "+qphrase+" ";
 
1360
                "  AND program.stars " + qphrase + ' ';
1364
1361
    }
1365
1362
    else if (m_type == plTime) // list by time
1366
1363
    {
1386
1383
    }
1387
1384
    else if (m_type == plStoredSearch) // stored search
1388
1385
    {
1389
 
        QString fromc, wherec;
1390
1386
        MSqlQuery query(MSqlQuery::InitCon());
1391
1387
        query.prepare("SELECT fromclause, whereclause FROM customexample "
1392
1388
                      "WHERE rulename = :RULENAME;");
1394
1390
 
1395
1391
        if (query.exec() && query.next())
1396
1392
        {
1397
 
            fromc  = query.value(0).toString();
1398
 
            wherec = query.value(1).toString();
 
1393
            QString fromc = query.value(0).toString();
 
1394
            QString wherec = query.value(1).toString();
1399
1395
 
1400
1396
            where = QString("WHERE channel.visible = 1 "
1401
1397
                            "  AND program.endtime > :PGILSTART "
1402
1398
                            "  AND ( %1 ) ").arg(wherec);
1403
 
            if (fromc > "")
1404
 
                where = fromc + " " + where;
 
1399
            if (!fromc.isEmpty())
 
1400
                where = fromc + ' ' + where;
1405
1401
        }
1406
1402
    }
1407
1403
    else if (m_type == plPreviouslyRecorded)
1455
1451
            // Prune to one per title
1456
1452
            sort(sortedList.begin(), sortedList.end(), plTitleSort());
1457
1453
 
1458
 
            QString curtitle = "";
 
1454
            QString curtitle;
1459
1455
            vector<ProgramInfo *>::iterator i = sortedList.begin();
1460
1456
            while (i != sortedList.end())
1461
1457
            {
1486
1482
    else
1487
1483
    {
1488
1484
        vector<ProgramInfo *>::iterator i = sortedList.begin();
1489
 
        for (; i != sortedList.end(); i++)
 
1485
        for (; i != sortedList.end(); ++i)
1490
1486
            m_itemList.append(*i);
1491
1487
    }
1492
1488
 
1530
1526
        m_progList->SetItemCurrent(i + 1, i + 1 - selectedOffset);
1531
1527
    }
1532
1528
 
1533
 
    if (selected)
1534
 
        delete selected;
 
1529
    delete selected;
1535
1530
}
1536
1531
 
1537
1532
void ProgLister::updateButtonList(void)
1767
1762
                         RecSearchType searchType,
1768
1763
                         const QStringList &list,
1769
1764
                         const QString &currentValue)
1770
 
            : MythScreenType(parentStack, "phrasepopup")
 
1765
            : MythScreenType(parentStack, "phrasepopup"),
 
1766
              m_parent(parent), m_searchType(searchType),  m_list(list),
 
1767
              m_titleText(NULL), m_phraseList(NULL), m_phraseEdit(NULL),
 
1768
              m_okButton(NULL), m_deleteButton(NULL), m_recordButton(NULL)
1771
1769
{
1772
 
    m_parent = parent;
1773
 
    m_list = list;
1774
1770
    m_currentValue = currentValue;
1775
 
    m_searchType = searchType;
1776
1771
}
1777
1772
 
1778
1773
bool PhrasePopup::Create()
1839
1834
 
1840
1835
void PhrasePopup::editChanged(void)
1841
1836
{
1842
 
    m_okButton->SetEnabled((m_phraseEdit->GetText().trimmed().length() > 0));
 
1837
    m_okButton->SetEnabled(!m_phraseEdit->GetText().trimmed().isEmpty());
1843
1838
    m_deleteButton->SetEnabled((m_list.indexOf(m_phraseEdit->GetText().trimmed()) != -1));
1844
 
    m_recordButton->SetEnabled((m_phraseEdit->GetText().trimmed().length() > 0));
 
1839
    m_recordButton->SetEnabled(!m_phraseEdit->GetText().trimmed().isEmpty());
1845
1840
}
1846
1841
 
1847
1842
void PhrasePopup::phraseClicked(MythUIButtonListItem *item)
1874
1869
 
1875
1870
void PhrasePopup::okClicked(void)
1876
1871
{
1877
 
    if (m_phraseEdit->GetText().trimmed().length() == 0)
 
1872
    if (m_phraseEdit->GetText().trimmed().isEmpty())
1878
1873
        return;
1879
1874
 
1880
1875
    // check to see if we need to save the phrase
1978
1973
///////////////////////////////////////////////////////////////////////////////
1979
1974
 
1980
1975
TimePopup::TimePopup(MythScreenStack *parentStack, ProgLister *parent)
1981
 
         : MythScreenType(parentStack, "timepopup")
 
1976
         : MythScreenType(parentStack, "timepopup"),
 
1977
           m_parent(parent), m_dateList(NULL), m_timeList(NULL),
 
1978
           m_okButton(NULL)
1982
1979
{
1983
 
    m_parent = parent;
1984
1980
}
1985
1981
 
1986
1982
bool TimePopup::Create()
2059
2055
                                   RecSearchType searchType,
2060
2056
                                   const QStringList &list,
2061
2057
                                   const QString &currentValue)
2062
 
            : MythScreenType(parentStack, "phrasepopup")
 
2058
            : MythScreenType(parentStack, "phrasepopup"),
 
2059
              m_parent(parent), m_searchType(searchType), m_list(list),
 
2060
              m_currentValue(currentValue),
 
2061
              m_titleText(NULL), m_phraseList(NULL), m_phraseEdit(NULL),
 
2062
              m_editButton(NULL), m_deleteButton(NULL), m_recordButton(NULL)
2063
2063
{
2064
 
    m_parent = parent;
2065
 
    m_list = list;
2066
 
    m_currentValue = currentValue;
2067
 
    m_searchType = searchType;
2068
2064
}
2069
2065
 
2070
2066
bool PowerSearchPopup::Create()
2266
2262
 
2267
2263
    //sanity check currentvalue
2268
2264
    m_currentValue = currentValue;
2269
 
    QStringList field = m_currentValue.split(":");
 
2265
    QStringList field = m_currentValue.split(':');
2270
2266
    if (field.count() != 6)
2271
2267
    {
2272
2268
        VERBOSE(VB_IMPORTANT, QString("Error. PowerSearch %1 has %2 fields")
2295
2291
        return false;
2296
2292
    }
2297
2293
 
2298
 
    QStringList field = m_currentValue.split(":");
 
2294
    QStringList field = m_currentValue.split(':');
2299
2295
 
2300
2296
    m_titleEdit->SetText(field[0]);
2301
2297
    m_subtitleEdit->SetText(field[1]);
2317
2313
 
2318
2314
void EditPowerSearchPopup::okClicked(void)
2319
2315
{
2320
 
    QString text = "";
2321
 
    text =  m_titleEdit->GetText().replace(":","%").replace("*","%") + ":";
2322
 
    text += m_subtitleEdit->GetText().replace(":","%").replace("*","%") + ":";
2323
 
    text += m_descEdit->GetText().replace(":","%").replace("*","%") + ":";
 
2316
    QString text;
 
2317
    text =  m_titleEdit->GetText().replace(':','%').replace('*','%') + ':';
 
2318
    text += m_subtitleEdit->GetText().replace(':','%').replace('*','%') + ':';
 
2319
    text += m_descEdit->GetText().replace(':','%').replace('*','%') + ':';
2324
2320
 
2325
2321
    if (m_categoryList->GetCurrentPos() > 0)
2326
2322
        text += m_categories[m_categoryList->GetCurrentPos()];
2327
 
    text += ":";
 
2323
    text += ':';
2328
2324
    if (m_genreList->GetCurrentPos() > 0)
2329
2325
        text += m_genres[m_genreList->GetCurrentPos()];
2330
 
    text += ":";
 
2326
    text += ':';
2331
2327
    if (m_channelList->GetCurrentPos() > 0)
2332
2328
        text += m_channels[m_channelList->GetCurrentPos()];
2333
2329
 
2343
2339
 
2344
2340
void EditPowerSearchPopup::initLists(void)
2345
2341
{
2346
 
    QStringList field = m_currentValue.split(":");
 
2342
    QStringList field = m_currentValue.split(':');
2347
2343
 
2348
2344
    // category type
2349
2345
    m_categories.clear();
2368
2364
 
2369
2365
    query.prepare("SELECT genre FROM programgenres GROUP BY genre;");
2370
2366
 
2371
 
    if (query.exec() && query.size())
 
2367
    if (query.exec())
2372
2368
    {
2373
2369
        while (query.next())
2374
2370
        {
2394
2390
    DBChanList channels = ChannelUtil::GetChannels(0, true, "callsign");
2395
2391
    ChannelUtil::SortChannels(channels, channelOrdering, true);
2396
2392
 
2397
 
    for (uint i = 0; i < channels.size(); i++)
 
2393
    for (uint i = 0; i < channels.size(); ++i)
2398
2394
    {
2399
2395
        QString chantext = channelFormat;
2400
2396
        chantext