Skip to content

Commit

Permalink
cli args add as new playlist (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
olegantonyan committed Oct 22, 2020
1 parent abb2876 commit 562e952
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ int main(int argc, char *argv[]) {

RNJesus::seed();

qDebug() << "starting" << a.applicationDisplayName();


QString lang = QLocale::system().name().split("_").first();
QTranslator trans;
Expand All @@ -34,7 +36,12 @@ int main(int argc, char *argv[]) {
}


MainWindow w;
QStringList args;
for (int i = 1; i < argc; i++) {
args << argv[i];
}

MainWindow w(args);
w.show();
return a.exec();
}
18 changes: 17 additions & 1 deletion app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QStyle>
#include <QEvent>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), trayicon(nullptr) {
MainWindow::MainWindow(const QStringList &args, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), trayicon(nullptr) {
#if defined(MPRIS_ENABLE)
mpris = nullptr;
#endif
Expand Down Expand Up @@ -68,6 +68,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
setupWindowTitle();
setupPlaybackLog();
setupSortMenu();

preloadPlaylist(args);
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -369,3 +371,17 @@ void MainWindow::setupSortMenu() {

//ui->sortButton->setIcon(style()->standardIcon(QStyle::SP_ArrowDown));
}

void MainWindow::preloadPlaylist(const QStringList &args) {
QList<QDir> preload_files;
for (auto i : args) {
preload_files << QDir(i);
}
if (!preload_files.isEmpty()) {
QEventLoop loop;
connect(playlists, &PlaylistsUi::Controller::selected, &loop, &QEventLoop::quit);
playlists->on_createPlaylist(preload_files);
loop.exec();
QTimer::singleShot(400, dispatch, &Playback::Dispatch::on_startRequested);
}
}
4 changes: 3 additions & 1 deletion app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MainWindow : public QMainWindow {
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
MainWindow(const QStringList &args, QWidget *parent = nullptr);
~MainWindow() override;

public slots:
Expand Down Expand Up @@ -77,6 +77,8 @@ public slots:
void setupWindowTitle();
void setupPlaybackLog();
void setupSortMenu();

void preloadPlaylist(const QStringList &args);

protected:
void closeEvent(QCloseEvent *event) override;
Expand Down

0 comments on commit 562e952

Please sign in to comment.