1
1
#include < QContextMenuEvent>
2
2
#include < QDebug>
3
- #include < QMenu>
4
3
#include < QSettings>
5
4
#include < QStandardPaths>
6
5
#include < QWebEngineFullScreenRequest>
@@ -25,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent)
25
24
QWebEngineSettings::globalSettings ()->setAttribute (
26
25
QWebEngineSettings::PluginsEnabled, true );
27
26
stateSettings = new QSettings (" Qtwebflix" , " Save State" , this );
28
- keySettings = new QSettings (" Qtwebflix" , " keybinds " , this );
27
+ appSettings = new QSettings (" Qtwebflix" , " qtwebflix " , this );
29
28
QWebEngineProfile::defaultProfile ()->setPersistentCookiesPolicy (
30
29
QWebEngineProfile::ForcePersistentCookies);
31
30
@@ -134,14 +133,18 @@ void MainWindow::registerMprisKeybinds() {
134
133
actions[" pause" ] = std::make_pair (mpris.get (), SLOT (pauseVideo ()));
135
134
actions[" play-pause" ] = std::make_pair (mpris.get (), SLOT (togglePlayPause ()));
136
135
actions[" next-episode" ] = std::make_pair (mpris.get (), SLOT (goNextEpisode ()));
136
+ actions[" seek-next" ] = std::make_pair (mpris.get (), SLOT (setSeek (10 )));
137
+ actions[" seek-prev" ] = std::make_pair (mpris.get (), SLOT (setSeek (-10 )));
137
138
138
- for (auto action : keySettings->allKeys ()) {
139
- auto keySequence = keySettings->value (action).toStringList ().join (' ,' );
139
+ appSettings->beginGroup (" keybinds" );
140
+ for (auto action : appSettings->allKeys ()) {
141
+ auto keySequence = appSettings->value (action).toStringList ().join (' ,' );
140
142
for (auto key :
141
143
keySequence.split (QRegExp (" \\ s+" ), QString::SkipEmptyParts)) {
142
144
registerShortcut (action, key);
143
145
}
144
146
}
147
+ appSettings->endGroup ();
145
148
}
146
149
147
150
void MainWindow::exchangeMprisInterfaceIfNeeded () {
@@ -278,7 +281,35 @@ void MainWindow::restore() {
278
281
restoreGeometry (geometryData);
279
282
}
280
283
281
- void MainWindow::readSettings () { restore (); }
284
+ void MainWindow::createContextMenu (const QStringList &keys) {
285
+ for (const auto &i : keys) {
286
+ if (!i.startsWith (" #" )) {
287
+ QString url = appSettings->value (i).toString ();
288
+ contextMenu.addAction (i, [this , url]() {
289
+ qDebug () << " URL is :" << url;
290
+ webview->setUrl (QUrl (url));
291
+ });
292
+ contextMenu.addSeparator ();
293
+ }
294
+ }
295
+ }
296
+
297
+ void MainWindow::readSettings () {
298
+ appSettings->beginGroup (" providers" );
299
+ QStringList providers = appSettings->allKeys ();
300
+
301
+ // Check if config file exists,if not create a default key.
302
+ if (!providers.size ()) {
303
+ qDebug () << " Config file does not exist, creating default" ;
304
+ appSettings->setValue (" netflix" , " http://netflix.com" );
305
+ appSettings->sync ();
306
+ providers = appSettings->allKeys ();
307
+ }
308
+ appSettings->endGroup ();
309
+ createContextMenu (providers);
310
+
311
+ restore ();
312
+ }
282
313
283
314
void MainWindow::fullScreenRequested (QWebEngineFullScreenRequest request) {
284
315
@@ -295,48 +326,8 @@ void MainWindow::fullScreenRequested(QWebEngineFullScreenRequest request) {
295
326
296
327
void MainWindow::ShowContextMenu (const QPoint &pos) // this is a slot
297
328
{
298
-
299
329
QPoint globalPos = webview->mapToGlobal (pos);
300
- provSettings = new QSettings (" Qtwebflix" , " Providers" , this );
301
- provSettings->setIniCodec (" UTF-8" );
302
- provSettings->beginGroup (" providers" );
303
- QString conf (provSettings->fileName ());
304
-
305
- // Check if config file exists,if not create a default key.
306
- if (!QFile::exists (conf))
307
-
308
- {
309
- qDebug () << " Config file does not exist, creating default" ;
310
- provSettings->setValue (" netflix" , " http://netflix.com" );
311
- provSettings->sync ();
312
- }
313
-
314
- QStringList keys = provSettings->allKeys ();
315
-
316
- QMenu myMenu;
317
- for (const auto &i : keys) {
318
- // qDebug() << "keys" << i;
319
-
320
- if (!i.startsWith (" #" )) {
321
- myMenu.addAction (i);
322
- myMenu.addSeparator ();
323
- }
324
- }
325
-
326
- QAction *selectedItem = myMenu.exec (globalPos);
327
-
328
- if (selectedItem == nullptr ) {
329
- return ;
330
- } else if (selectedItem) {
331
- QString url = provSettings->value (selectedItem->text ()).toString ();
332
- qDebug () << " URL is :" << url;
333
- webview->setUrl (QUrl (url));
334
- provSettings->endGroup ();
335
- }
336
-
337
- else {
338
- // nothing was chosen
339
- }
330
+ QAction *selectedItem = contextMenu.exec (globalPos);
340
331
}
341
332
342
333
void MainWindow::parseCommand () {
0 commit comments