Switch to unified view

a/dirbrowser/cdbrowser.cpp b/dirbrowser/cdbrowser.cpp
...
...
46
#include <QMessageBox>
46
#include <QMessageBox>
47
#include <QMenu>
47
#include <QMenu>
48
#include <QApplication>
48
#include <QApplication>
49
#include <QByteArray>
49
#include <QByteArray>
50
#include <QProgressDialog>
50
#include <QProgressDialog>
51
#include <QClipboard>
51
52
52
#include "HelperStructs/Helper.h"
53
#include "HelperStructs/Helper.h"
54
#include "HelperStructs/Style.h"
53
#include "HelperStructs/CSettingsStorage.h"
55
#include "HelperStructs/CSettingsStorage.h"
54
56
55
#include "libupnpp/log.hxx"
57
#include "libupnpp/log.hxx"
56
#include "libupnpp/control/discovery.hxx"
58
#include "libupnpp/control/discovery.hxx"
57
59
...
...
70
72
71
static const string minimFoldersViewPrefix("0$folders");
73
static const string minimFoldersViewPrefix("0$folders");
72
74
73
static void msleep(int millis)
75
static void msleep(int millis)
74
{
76
{
75
    struct timespec spec;
77
struct timespec spec;
76
    spec.tv_sec = millis / 1000;
78
spec.tv_sec = millis / 1000;
77
    spec.tv_nsec = (millis % 1000) * 1000000;
79
spec.tv_nsec = (millis % 1000) * 1000000;
78
    nanosleep(&spec, 0);
80
nanosleep(&spec, 0);
79
}
81
}
80
82
81
void CDWebPage::javaScriptConsoleMessage(
83
void CDWebPage::javaScriptConsoleMessage(
82
#ifdef USING_WEBENGINE
84
#ifdef USING_WEBENGINE
83
    JavaScriptConsoleMessageLevel,
85
JavaScriptConsoleMessageLevel,
84
#endif
86
#endif
85
    const QString& msg, int lineNum, const QString&)
87
    const QString& msg, int lineNum, const QString&)
86
{
88
{
87
    Q_UNUSED(msg);
89
Q_UNUSED(msg);
88
    Q_UNUSED(lineNum);
90
Q_UNUSED(lineNum);
89
    LOGDEB("JAVASCRIPT: "<< qs2utf8s(msg) << " at line " << lineNum << endl);
91
LOGDEB("JAVASCRIPT: "<< qs2utf8s(msg) << " at line " << lineNum << endl);
90
}
92
}
91
93
92
static const QString html_top_orig = QString::fromUtf8(
94
static const QString html_top_orig = QString::fromUtf8(
93
    "<html><head>"
95
"<html><head>"
94
    "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"
96
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"
95
    );
97
);
96
98
97
// The const part + the js we need for webengine
99
// The const part + the js we need for webengine
98
static QString html_top_js;
100
static QString html_top_js;
99
// The const part + the js + changeable style, computed as needed.
101
// The const part + the js + changeable style, computed as needed.
100
static QString html_top;
102
static QString html_top;
101
103
102
CDBrowser::CDBrowser(QWidget* parent)
104
CDBrowser::CDBrowser(QWidget* parent)
103
    : QWEBVIEW(parent), m_reader(0), m_reaper(0), m_progressD(0),
105
    : QWEBVIEW(parent), m_reader(0), m_reaper(0), m_progressD(0),
104
      m_browsers(0), m_lastbutton(Qt::LeftButton), m_sysUpdId(0)
106
      m_browsers(0), m_lastbutton(Qt::LeftButton), m_sysUpdId(0)
105
{
107
{
106
    setPage(new CDWebPage(this));
108
setPage(new CDWebPage(this));
107
    
109
    
108
#ifdef USING_WEBENGINE
110
#ifdef USING_WEBENGINE
109
    if (html_top_js.isEmpty()) {
111
if (html_top_js.isEmpty()) {
110
        QLoggingCategory("js").setEnabled(QtDebugMsg, true);
112
QLoggingCategory("js").setEnabled(QtDebugMsg, true);
111
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
113
#if !defined(Q_OS_MACOS) && !defined(Q_OS_MAC)
112
        QString jsfn = Helper::getSharePath() + "/cdbrowser/containerscript.js";
114
QString jsfn = Helper::getSharePath() + "/cdbrowser/containerscript.js";
113
#else
115
#else
114
        QString jsfn = Helper::getSharePath() + "/Resources/containerscript.js";
116
QString jsfn = Helper::getSharePath() + "/Resources/containerscript.js";
115
#endif
117
#endif
116
        QString js = "<script type=\"text/javascript\">\n";
118
QString js = "<script type=\"text/javascript\">\n";
117
        js += QString::fromUtf8(Helper::readFileToByteArray(jsfn));
119
js += QString::fromUtf8(Helper::readFileToByteArray(jsfn));
118
        js += "</script>\n";
120
js += "</script>\n";
119
        html_top_js = html_top + js;
121
html_top_js = html_top + js;
120
    }
122
}
121
#else
123
#else
122
    html_top_js = html_top;
124
html_top_js = html_top;
123
    connect(this, SIGNAL(linkClicked(const QUrl &)), 
125
connect(this, SIGNAL(linkClicked(const QUrl &)), 
124
            this, SLOT(onLinkClicked(const QUrl &)));
126
            this, SLOT(onLinkClicked(const QUrl &)));
125
    // Not available and not sure that this is needed with webengine ?
127
// Not available and not sure that this is needed with webengine ?
126
    connect(page()->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)),
128
connect(page()->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)),
127
            this, SLOT(onContentsSizeChanged(const QSize&)));
129
            this, SLOT(onContentsSizeChanged(const QSize&)));
128
    page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
130
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
129
#endif
131
#endif
130
132
131
    // This sets html_top
133
// This sets html_top
132
    setStyleSheet(CSettingsStorage::getInstance()->getPlayerStyle(), false);
134
setStyleSheet(CSettingsStorage::getInstance()->getPlayerStyle(), false);
133
    
135
    
134
    settings()->setAttribute(QWEBSETTINGS::JavascriptEnabled, true);
136
settings()->setAttribute(QWEBSETTINGS::JavascriptEnabled, true);
135
    if (parent) {
137
if (parent) {
136
        settings()->setFontSize(QWEBSETTINGS::DefaultFontSize, 
138
settings()->setFontSize(QWEBSETTINGS::DefaultFontSize, 
137
                              parent->font().pointSize()+4);
139
                        parent->font().pointSize()+4);
138
  settings()->setFontFamily(QWEBSETTINGS::StandardFont, 
140
settings()->setFontFamily(QWEBSETTINGS::StandardFont, 
139
                 parent->font().family());
141
                          parent->font().family());
140
    }
142
}
141
    setContextMenuPolicy(Qt::CustomContextMenu);
143
setContextMenuPolicy(Qt::CustomContextMenu);
142
    connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
144
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
143
      this, SLOT(createPopupMenu(const QPoint&)));
145
        this, SLOT(createPopupMenu(const QPoint&)));
144
    m_timer.setSingleShot(1);
146
m_timer.setSingleShot(1);
145
    connect(&m_timer, SIGNAL(timeout()), this, SLOT(initialPage()));
147
connect(&m_timer, SIGNAL(timeout()), this, SLOT(initialPage()));
146
    m_timer.start(0);
148
m_timer.start(0);
147
}
149
}
148
150
149
CDBrowser::~CDBrowser()
151
CDBrowser::~CDBrowser()
150
{
152
{
151
    deleteReaders();
153
    deleteReaders();
...
...
181
#else
183
#else
182
    QString cssfn = Helper::getSharePath() + "/cdbrowser/cdbrowser.css";
184
    QString cssfn = Helper::getSharePath() + "/cdbrowser/cdbrowser.css";
183
#endif
185
#endif
184
    QString cssdata = QString::fromUtf8(Helper::readFileToByteArray(cssfn));
186
    QString cssdata = QString::fromUtf8(Helper::readFileToByteArray(cssfn));
185
187
188
    float multiplier = QSettings().value("wholeuiscale").toFloat();
189
    if (multiplier == 0)
190
        multiplier = 1.0;
191
    cssdata = u8s2qs(Style::scale_fonts(qs2utf8s(cssdata), multiplier));
192
    
186
    if (dark) {
193
    if (dark) {
187
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
194
#if defined(Q_OS_MACOS) || defined(Q_OS_MAC)
188
        cssfn = Helper::getSharePath() + "/Resources/dark.css";
195
        cssfn = Helper::getSharePath() + "/Resources/dark.css";
189
#else
196
#else
190
        cssfn = Helper::getSharePath() + "/cdbrowser/dark.css";
197
        cssfn = Helper::getSharePath() + "/cdbrowser/dark.css";
...
...
963
    PUP_OPEN_IN_NEW_TAB,
970
    PUP_OPEN_IN_NEW_TAB,
964
    PUP_RAND_PLAY_TRACKS,
971
    PUP_RAND_PLAY_TRACKS,
965
    PUP_RAND_PLAY_GROUPS,
972
    PUP_RAND_PLAY_GROUPS,
966
    PUP_RAND_STOP,
973
    PUP_RAND_STOP,
967
    PUP_SORT_ORDER,
974
    PUP_SORT_ORDER,
975
    PUP_COPY_URL,
968
};
976
};
969
977
970
void CDBrowser::onLoadFinished(bool)
978
void CDBrowser::onLoadFinished(bool)
971
{
979
{
972
    LOGDEB("CDBrowser::onLoadFinished\n");
980
    LOGDEB("CDBrowser::onLoadFinished\n");
...
...
1084
1092
1085
        act = new QAction(tr("Send all from here to playlist"), this);
1093
        act = new QAction(tr("Send all from here to playlist"), this);
1086
        v = QVariant(int(PUP_ADD_FROMHERE));
1094
        v = QVariant(int(PUP_ADD_FROMHERE));
1087
        act->setData(v);
1095
        act->setData(v);
1088
        popup->addAction(act);
1096
        popup->addAction(act);
1097
1098
        act = new QAction(tr("Copy URL"), this);
1099
        v = QVariant(int(PUP_COPY_URL));
1100
        act->setData(v);
1101
        popup->addAction(act);
1089
    }
1102
    }
1090
   
1103
   
1091
    // Connect to either recursive add or simpleAdd depending on entry type.
1104
    // Connect to either recursive add or simpleAdd depending on entry type.
1092
    if (!m_popupotype.compare("container")) {
1105
    if (!m_popupotype.compare("container")) {
1093
        act = new QAction(tr("Open in new tab"), this);
1106
        act = new QAction(tr("Open in new tab"), this);
...
...
1173
        return;
1186
        return;
1174
    }
1187
    }
1175
    MetaDataList mdl;
1188
    MetaDataList mdl;
1176
    unsigned int starti = 0;
1189
    unsigned int starti = 0;
1177
    switch (m_popupmode) {
1190
    switch (m_popupmode) {
1191
    case PUP_COPY_URL:
1192
    {
1193
        UPnPDirObject& e(m_entries[m_popupidx]);
1194
        if (e.m_resources.empty()) {
1195
            
1196
        }
1197
        QString uri = QString::fromLocal8Bit(e.m_resources[0].m_uri.c_str());
1198
        QApplication::clipboard()->setText(uri, QClipboard::Selection);
1199
        QApplication::clipboard()->setText(uri, QClipboard::Clipboard);
1200
        return;
1201
    }
1178
    case PUP_ADD_FROMHERE: 
1202
    case PUP_ADD_FROMHERE: 
1179
        starti = m_popupidx;
1203
        starti = m_popupidx;
1180
        /* FALLTHROUGH */
1204
        /* FALLTHROUGH */
1181
    case PUP_ADD_ALL:
1205
    case PUP_ADD_ALL:
1182
        for (unsigned int i = starti; i < m_entries.size(); i++) {
1206
        for (unsigned int i = starti; i < m_entries.size(); i++) {