Switch to unified view

a/dirbrowser/cdbrowser.cpp b/dirbrowser/cdbrowser.cpp
...
...
120
    m_timer.start(0);
120
    m_timer.start(0);
121
}
121
}
122
122
123
CDBrowser::~CDBrowser()
123
CDBrowser::~CDBrowser()
124
{
124
{
125
    deleteReaders();
125
    deleteReaders("~CDBrowser");
126
}
126
}
127
127
128
void CDBrowser::mySetHtml(const QString& html)
128
void CDBrowser::mySetHtml(const QString& html)
129
{
129
{
130
    // Tried to wait using an event loop, but it seems that the
130
    // Tried to wait using an event loop, but it seems that the
...
...
137
    setHtml(html);
137
    setHtml(html);
138
    Helper::msleep(100);
138
    Helper::msleep(100);
139
    //pause.exec();
139
    //pause.exec();
140
}
140
}
141
141
142
#ifndef USING_WEBENGINE
143
void CDBrowser::onContentsSizeChanged(const QSize&)
144
{
145
    //qDebug() << "CDBrowser::onContentsSizeChanged: scrollpos " <<
146
    // page()->mainFrame()->scrollPosition();
147
    //qDebug() << "164 - m_savedscrollpos: " << m_savedscrollpos;
148
    page()->mainFrame()->setScrollPosition(m_savedscrollpos);
149
}
142
void CDBrowser::mouseReleaseEvent(QMouseEvent *event)
150
void CDBrowser::mouseReleaseEvent(QMouseEvent *event)
143
{
151
{
144
    //qDebug() << "CDBrowser::mouseReleaseEvent";
152
    //qDebug() << "CDBrowser::mouseReleaseEvent";
145
    m_lastbutton = event->button();
153
    m_lastbutton = event->button();
146
    QWEBVIEW::mouseReleaseEvent(event);
154
    QWEBVIEW::mouseReleaseEvent(event);
...
...
158
        QUrl url(surl);
166
        QUrl url(surl);
159
        onLinkClicked(url);
167
        onLinkClicked(url);
160
    }
168
    }
161
    QWEBVIEW::keyPressEvent(e);
169
    QWEBVIEW::keyPressEvent(e);
162
}
170
}
171
void CDBrowser::runJS(const QString& js)
172
{
173
    //qDebug() << "CDBrowser::runJS: " << js;
174
    page()->mainFrame()->evaluateJavaScript(js);
175
}
176
177
#else // Webengine->
163
178
164
void CDBrowser::onContentsSizeChanged(const QSize&)
179
void CDBrowser::onContentsSizeChanged(const QSize&)
165
{
180
{
166
    //qDebug() << "CDBrowser::onContentsSizeChanged: scrollpos " <<
181
    //qDebug() << "CDBrowser::onContentsSizeChanged: scrollpos " <<
167
    // page()->mainFrame()->scrollPosition();
182
    // page()->mainFrame()->scrollPosition();
168
    //qDebug() << "164 - m_savedscrollpos: " << m_savedscrollpos;
183
    //qDebug() << "164 - m_savedscrollpos: " << m_savedscrollpos;
169
#ifdef USING_WEBENGINE
170
    QString js = "window.scrollBy(" + 
184
    QString js = "window.scrollBy(" + 
171
        QString::number(m_savedscrollpos.x())+ ", " +
185
        QString::number(m_savedscrollpos.x())+ ", " +
172
        QString::number(m_savedscrollpos.y()) + ");";
186
        QString::number(m_savedscrollpos.y()) + ");";
173
    runJS(js);
187
    runJS(js);
174
#else
175
    page()->mainFrame()->setScrollPosition(m_savedscrollpos);
176
#endif
177
}
188
}
178
179
#ifdef USING_WEBENGINE
180
static QString base64_encode(QString string)
189
static QString base64_encode(QString string)
181
{
190
{
182
    QByteArray ba;
191
    QByteArray ba;
183
    ba.append(string);
192
    ba.append(string);
184
    return ba.toBase64();
193
    return ba.toBase64();
185
}
194
}
195
void CDBrowser::onJSRan(const QVariant&)
196
{
197
    m_somethingran = true;
198
}
199
void CDBrowser::runJS(const QString& js)
200
{
201
    //qDebug() << "CDBrowser::runJS: " << js;
202
    page()->runJavaScript(js, [this](const QVariant &v) { onJSRan(v);});
203
}
204
186
#endif
205
#endif
187
206
188
void CDBrowser::runJS(const QString& js)
189
{
190
    //qDebug() << "CDBrowser::runJS: " << js;
191
192
#ifdef USING_WEBENGINE
193
    page()->runJavaScript(js, [] (QVariant res) {
194
            Q_UNUSED(res);
195
        });
196
#else
197
    page()->mainFrame()->evaluateJavaScript(js);
198
#endif
199
200
}
201
207
202
void CDBrowser::appendHtml(const QString& elt_id, const QString& html)
208
void CDBrowser::appendHtml(const QString& elt_id, const QString& html)
203
{
209
{
204
    LOGDEB1("CDBrowser::appendHtml: elt_id [" << qs2utf8s(elt_id) <<
210
    LOGDEB1("CDBrowser::appendHtml: elt_id [" << qs2utf8s(elt_id) <<
205
            "] html "<< qs2utf8s(html) << endl);
211
            "] html "<< qs2utf8s(html) << endl);
...
...
333
// automatic calls (when seeing a container with a single container
339
// automatic calls (when seeing a container with a single container
334
// entry for example, and to avoid unlimited recursion on a pathologic tree).
340
// entry for example, and to avoid unlimited recursion on a pathologic tree).
335
void CDBrowser::onLinkClicked(const QUrl &url)
341
void CDBrowser::onLinkClicked(const QUrl &url)
336
{
342
{
337
    m_autoclickcnt = 0;
343
    m_autoclickcnt = 0;
344
    deleteReaders("onLinkClicked event");
338
    processOnLinkClicked(url);
345
    processOnLinkClicked(url);
339
}
346
}
340
347
341
void CDBrowser::processOnLinkClicked(const QUrl &url)
348
void CDBrowser::processOnLinkClicked(const QUrl &url)
342
{
349
{
...
...
437
444
438
void CDBrowser::curpathClicked(unsigned int i)
445
void CDBrowser::curpathClicked(unsigned int i)
439
{
446
{
440
    LOGDEB1("CDBrowser::curpathClicked: " << i << " pathsize " << 
447
    LOGDEB1("CDBrowser::curpathClicked: " << i << " pathsize " << 
441
            m_curpath.size() << endl);
448
            m_curpath.size() << endl);
449
    if (m_reader || m_reaper) {
450
        LOGDEB("CDBrowser::curpathClicked: already active\n");
451
        return;
452
    }
442
    if (i >= m_curpath.size()) {
453
    if (i >= m_curpath.size()) {
443
        LOGERR("CDBrowser::curPathClicked: bad curpath index: " << i 
454
        LOGERR("CDBrowser::curPathClicked: bad curpath index: " << i 
444
               << " path count: " << m_curpath.size() << endl);
455
               << " path count: " << m_curpath.size() << endl);
445
        return;
456
        return;
446
    }
457
    }
...
...
476
        }
487
        }
477
    }
488
    }
478
    return -1;
489
    return -1;
479
}
490
}
480
491
492
// This is called for browsing a specific container in a newly created
493
// tab.  We let initialPage handle the hard work.
481
void CDBrowser::browseIn(QString UDN, vector<CtPathElt> path)
494
void CDBrowser::browseInNewTab(QString UDN, vector<CtPathElt> path)
482
{
495
{
483
    //qDebug() << "CDBrowser::browsein: " << UDN;
496
    //qDebug() << "CDBrowser::browseinnewtab: " << UDN;
484
497
485
    m_curpath = path;
498
    m_curpath = path;
486
487
    if (m_msdescs.size() == 0) {
488
        // If the servers list is not ready yet, just set m_initUDN to tell
489
        // initialPage() to do the right thing later when it gets the servers
490
        // qDebug() << "CDBrowser::browsein: no servers";
491
        m_initUDN = UDN;
499
    m_initUDN = UDN;
500
    m_timer.stop();
501
    m_timer.start(0);
492
        return;
502
    return;
493
    } 
494
495
    m_lastbutton = Qt::LeftButton;
496
497
    // Find UDN in msdescs, create a MediaServer object, and read the
498
    // specified container (last in input curpath)
499
    int i = serverFromUDN(qs2utf8s(UDN));
500
    if (i >= 0) {
501
        newCds(i);
502
        curpathClicked(path.size() - 1);
503
        return;
504
    }
505
    qDebug() << "CDBrowser::browsein: " << UDN << " not found";
506
}
503
}
507
504
508
// Re-browse (because sort criteria changed probably)
505
// Re-browse (because sort criteria changed, or other prefs)
506
// if m_cds is not set, let initialPage() do its thing
509
void CDBrowser::refresh()
507
void CDBrowser::refresh()
510
{
508
{
509
    qDebug() << "CDBrowser::refresh";
511
    if (m_curpath.size() >= 1) {
510
    if (m_cds && m_curpath.size() >= 1) {
511
        setStyleSheet(CSettingsStorage::getInstance()->getPlayerStyle(), false);
512
        curpathClicked(m_curpath.size() - 1);
512
        curpathClicked(m_curpath.size() - 1);
513
    }
513
    }
514
}
514
}
515
515
516
void CDBrowser::browseContainer(string ctid, string cttitle, bool ispl,
516
void CDBrowser::browseContainer(string ctid, string cttitle, bool ispl,
517
                                QPoint scrollpos)
517
                                QPoint scrollpos)
518
{
518
{
519
    LOGDEB("CDBrowser::browseContainer: " << " ctid " << ctid << endl);
519
    LOGDEB("CDBrowser::browseContainer: " << " ctid " << ctid << endl);
520
    deleteReaders();
520
    if (m_reader || m_reaper) {
521
        LOGDEB("CDBrowser::browseContainer: already active\n");
522
        return;
523
    }
521
524
522
    emit sig_now_in(this, QString::fromUtf8(cttitle.c_str()));
525
    emit sig_now_in(this, QString::fromUtf8(cttitle.c_str()));
523
526
524
    m_savedscrollpos = scrollpos;
527
    m_savedscrollpos = scrollpos;
525
    if (!m_cds) {
528
    if (!m_cds) {
...
...
545
    search(m_curpath.back().objid, iss);
548
    search(m_curpath.back().objid, iss);
546
}
549
}
547
550
548
void CDBrowser::search(const string& objid, const string& iss, QPoint scrollpos)
551
void CDBrowser::search(const string& objid, const string& iss, QPoint scrollpos)
549
{
552
{
550
    deleteReaders();
553
    deleteReaders("search");
551
    if (iss.empty())
554
    if (iss.empty())
552
        return;
555
        return;
553
    if (!m_cds) {
556
    if (!m_cds) {
554
        LOGERR("CDBrowser::search: server not set" << endl);
557
        LOGERR("CDBrowser::search: server not set" << endl);
555
        return;
558
        return;
...
...
566
    connect(m_reader, SIGNAL(done(int)), this, SLOT(onBrowseDone(int)));
569
    connect(m_reader, SIGNAL(done(int)), this, SLOT(onBrowseDone(int)));
567
    m_reader->start();
570
    m_reader->start();
568
}
571
}
569
572
570
573
571
void CDBrowser::deleteReaders() 
574
void CDBrowser::deleteReaders(const QString& who)
572
{
575
{
576
    Q_UNUSED(who);
573
    //qDebug() << "deleteReaders()";
577
//    qDebug() << "deleteReaders(): from " << who;
574
    if (m_reader) {
578
    if (m_reader) {
575
        m_reader->setCancel();
579
        m_reader->setCancel();
576
        m_reader->wait();
580
        m_reader->wait();
577
        delete m_reader;
581
        delete m_reader;
578
        m_reader = 0;
582
        m_reader = 0;
...
...
722
        LOGDEB("CDBrowser::onBrowseDone(int) no reader: cancelled\n");
726
        LOGDEB("CDBrowser::onBrowseDone(int) no reader: cancelled\n");
723
        return;
727
        return;
724
    }
728
    }
725
    if (m_autoclickcnt++ < 3 && m_entries.size() == 1 &&
729
    if (m_autoclickcnt++ < 3 && m_entries.size() == 1 &&
726
        m_entries[0].m_type == UPnPDirObject::container) {
730
        m_entries[0].m_type == UPnPDirObject::container) {
731
        deleteReaders("onBrowseDone");
727
        QUrl cturl(QString("http://h/C%1").arg(0));
732
        QUrl cturl(QString("http://h/C%1").arg(0));
728
        processOnLinkClicked(cturl);
733
        processOnLinkClicked(cturl);
729
        return;
734
        return;
730
    }
735
    }
731
        
736
        
...
...
789
        QString::number(m_savedscrollpos.y()) + ");";
794
        QString::number(m_savedscrollpos.y()) + ");";
790
    runJS(js);
795
    runJS(js);
791
#else
796
#else
792
    page()->mainFrame()->setScrollPosition(m_savedscrollpos);
797
    page()->mainFrame()->setScrollPosition(m_savedscrollpos);
793
#endif
798
#endif
794
    deleteReaders();
799
    deleteReaders("onBrowseDone");
795
800
796
    //qDebug() << "CDBrowser::onBrowseDone done";
801
    //qDebug() << "CDBrowser::onBrowseDone done";
797
}
802
}
798
803
799
804
800
void CDBrowser::initialPage(bool redisplay)
805
void CDBrowser::initialPage(bool redisplay)
801
{
806
{
807
    //qDebug() << "CDBrowser::initialPage. m_initUDN" << m_initUDN <<
808
    //" curpath size " << m_curpath.size();
802
#ifdef USING_WEBENGINE
809
#ifdef USING_WEBENGINE
803
    // No idea why this is necessary, but, only in the first tab, we
810
    // No idea why this is necessary, but, only in the first tab, we
804
    // have to force a few redisplays with webengine before something
811
    // have to force a few redisplays with webengine before something
805
    // shows.
812
    // shows.
806
    static int count;
813
    static int count;
807
    if (count++ < 10) {
814
    if (count++ < 10) {
808
        redisplay = true;
815
        redisplay = true;
809
    }
816
    }
810
#endif
817
#endif
811
    deleteReaders();
818
    deleteReaders("initialPage");
812
    emit sig_now_in(this, tr("Servers"));
819
    emit sig_now_in(this, tr("Servers"));
813
    m_searchcaps.clear();
820
    m_searchcaps.clear();
814
    emit sig_searchcaps_changed();
821
    emit sig_searchcaps_changed();
815
822
823
    if (m_msdescs.size() == 0) {
824
        mySetHtml(initialServersPage());
825
    }
826
816
    vector<UPnPDeviceDesc> msdescs;
827
    vector<UPnPDeviceDesc> msdescs;
817
    if (!MediaServer::getDeviceDescs(msdescs)) {
828
    if (!MediaServer::getDeviceDescs(msdescs)) {
818
        LOGERR("CDBrowser::initialPage: getDeviceDescs failed" << endl);
829
        LOGERR("CDBrowser::initialPage: getDeviceDescs failed" << endl);
830
        m_timer.start(1000);
819
        return;
831
        return;
820
    }
832
    }
821
    //qDebug() << "CDBrowser::initialPage: " << msdescs.size() << " servers";
833
    //qDebug() << "CDBrowser::initialPage: " << msdescs.size() << " servers";
822
834
823
    if (msdescs.size() == 0) {
835
    // Check if servers list changed
824
        mySetHtml(initialServersPage());
825
        m_timer.start(1000);
826
        return;
827
    }
828
829
    bool same = msdescs.size() == m_msdescs.size();
836
    bool same = msdescs.size() == m_msdescs.size();
830
    if (same) {
837
    if (same) {
831
        for (unsigned i = 0; i < msdescs.size(); i++) {
838
        for (unsigned i = 0; i < msdescs.size(); i++) {
832
            if (msdescs[i].UDN.compare(m_msdescs[i].UDN)) {
839
            if (msdescs[i].UDN.compare(m_msdescs[i].UDN)) {
833
                same = false;
840
                same = false;
834
                break;
841
                break;
835
            }
842
            }
836
        }
843
        }
837
    }
844
    }
838
    if (same && !redisplay) {
845
    if (!same) {
846
        m_msdescs = msdescs;
847
    }
848
    // If the list did not change and a redisplay was not requested,
849
    // do nothing
850
    if (same && !redisplay && m_initUDN.isEmpty()) {
839
        LOGDEB1("CDBrowser::initialPage: no change" << endl);
851
        //qDebug() << "CDBrowser::initialPage: no change";
840
        m_timer.start(1000);
852
        m_timer.start(1000);
841
        return;
853
        return;
842
    }
854
    }
843
    m_msdescs = msdescs;
844
855
845
    if (!m_initUDN.isEmpty()) {
856
    // Displaying stuff
857
858
    if (!m_initUDN.isEmpty() && m_curpath.size() > 1
859
#ifdef USING_WEBENGINE
860
        && m_somethingran
861
#endif
862
        ) {
863
        // Called from browseinnewtab, with specified server and path
864
        // (either midclick or restoring from stored state): show
865
        // appropriate container
846
        int i = serverFromUDN(qs2utf8s(m_initUDN));
866
        int i = serverFromUDN(qs2utf8s(m_initUDN));
867
        //qDebug() << "initialPage: serverFromUDN returned " << i;
847
        if (i >= 0) {
868
        if (i >= 0) {
848
            // "Browse in new tab": show appropriate container
869
            if (newCds(i)) {
849
            QString s = m_initUDN;
850
            m_initUDN = "";
870
                m_initUDN = "";
851
            browseIn(s, m_curpath);
871
                curpathClicked(m_curpath.size() - 1);
852
            return;
872
                return;
873
            }
853
        }
874
        }
854
    }
875
    }
855
876
856
    // No initUDN or not found: show servers list
877
    // No initUDN or not found: show servers list
857
    QString html = emptyServersPage();
878
    mySetHtml(emptyServersPage());
858
    m_alphamap.clear();
859
    mySetHtml(html);
860
    //char curinitial = 0;
861
    for (unsigned i = 0; i < msdescs.size(); i++) {
879
    for (unsigned i = 0; i < msdescs.size(); i++) {
862
        // Alphamap does not really work for servers, which are not in
880
        // Alphamap does not really work for servers, which are not in
863
        // alphabetic order at the moment
881
        // alphabetic order at the moment
864
        // updateAlphamap(curinitial, msdescs[i].friendlyName);
882
        // updateAlphamap(curinitial, msdescs[i].friendlyName);
865
        appendHtml("", DSToHtml(i, msdescs[i]));
883
        appendHtml("", DSToHtml(i, msdescs[i]));
...
...
878
    PUP_RAND_STOP,
896
    PUP_RAND_STOP,
879
    PUP_SORT_ORDER,
897
    PUP_SORT_ORDER,
880
    PUP_COPY_URL,
898
    PUP_COPY_URL,
881
};
899
};
882
900
883
void CDBrowser::onLoadFinished(bool)
901
#ifdef USING_WEBENGINE
884
{
885
    LOGDEB("CDBrowser::onLoadFinished\n");
886
}
887
888
void CDBrowser::onPopupJsDone(const QVariant &jr)
902
void CDBrowser::onPopupJsDone(const QVariant &jr)
889
{
903
{
890
    QString qs(jr.toString());
904
    QString qs(jr.toString());
891
    LOGDEB("onPopupJsDone: parameter: " << qs2utf8s(qs) << endl);
905
    LOGDEB("onPopupJsDone: parameter: " << qs2utf8s(qs) << endl);
892
    QStringList qsl = qs.split("\n", QString::SkipEmptyParts);
906
    QStringList qsl = qs.split("\n", QString::SkipEmptyParts);
...
...
914
           "] objid [" << m_popupobjid <<
928
           "] objid [" << m_popupobjid <<
915
           "] title [" <<  m_popupobjtitle <<
929
           "] title [" <<  m_popupobjtitle <<
916
           "] objidx [" << m_popupidx << "]\n");
930
           "] objidx [" << m_popupidx << "]\n");
917
    doCreatePopupMenu();
931
    doCreatePopupMenu();
918
}
932
}
933
#endif
919
934
920
void CDBrowser::createPopupMenu(const QPoint& pos)
935
void CDBrowser::createPopupMenu(const QPoint& pos)
921
{
936
{
922
    if (!m_browsers || m_browsers->insertActive()) {
937
    if (!m_browsers || m_browsers->insertActive()) {
923
        LOGDEB("CDBrowser::createPopupMenu: no popup: insert active\n");
938
        LOGDEB("CDBrowser::createPopupMenu: no popup: insert active\n");
...
...
1143
// Recursive add. This is triggered popup on a container
1158
// Recursive add. This is triggered popup on a container
1144
void CDBrowser::recursiveAdd(QAction *act)
1159
void CDBrowser::recursiveAdd(QAction *act)
1145
{
1160
{
1146
    //qDebug() << "CDBrowser::recursiveAdd";
1161
    //qDebug() << "CDBrowser::recursiveAdd";
1147
1162
1148
    deleteReaders();
1163
    deleteReaders("recursiveAdd");
1149
1164
1150
    if (popupOther(act)) {
1165
    if (popupOther(act)) {
1151
        // Not for us
1166
        // Not for us
1152
        return;
1167
        return;
1153
    }
1168
    }
...
...
1262
1277
1263
void CDBrowser::rreaperDone(int status)
1278
void CDBrowser::rreaperDone(int status)
1264
{
1279
{
1265
    LOGDEB("CDBrowser::rreaperDone: status: " << status << ". Entries: " <<
1280
    LOGDEB("CDBrowser::rreaperDone: status: " << status << ". Entries: " <<
1266
           m_recwalkentries.size() << endl);
1281
           m_recwalkentries.size() << endl);
1267
    deleteReaders();
1282
    deleteReaders("rreaperDone");
1268
    delete m_progressD;
1283
    delete m_progressD;
1269
    m_progressD = 0;
1284
    m_progressD = 0;
1270
    if (m_popupmode == PUP_RAND_PLAY_TRACKS ||
1285
    if (m_popupmode == PUP_RAND_PLAY_TRACKS ||
1271
        m_popupmode == PUP_RAND_PLAY_GROUPS) {
1286
        m_popupmode == PUP_RAND_PLAY_GROUPS) {
1272
        if (m_browsers)
1287
        if (m_browsers)