summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fsview.cpp50
-rw-r--r--src/fsview.hpp30
-rw-r--r--src/main.cpp15
-rw-r--r--src/maindialog.cpp44
-rw-r--r--src/maindialog.hpp29
-rw-r--r--src/maindialog.ui100
6 files changed, 268 insertions, 0 deletions
diff --git a/src/fsview.cpp b/src/fsview.cpp
new file mode 100644
index 0000000..3e9495e
--- /dev/null
+++ b/src/fsview.cpp
@@ -0,0 +1,50 @@
+/* ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "fsview.hpp"
+#include <QFileSystemModel>
+#include <QMenu>
+
+FSView::FSView(QWidget *parent) : QTreeView(parent), model{new QFileSystemModel}
+{
+ setModel(model);
+ setRootPath(QDir::homePath());
+
+ connect(this, &QWidget::customContextMenuRequested, this, &FSView::contextMenu);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+}
+
+FSView::~FSView() { delete model; }
+
+void FSView::setRootPath(const QString &path)
+{
+ model->setRootPath(path);
+ setRootIndex(model->index(path));
+}
+
+void FSView::contextMenu(const QPoint &pos)
+{
+ const auto idx = indexAt(pos);
+ if (idx.isValid()) {
+ QMenu menu;
+
+ if (model->isDir(idx)) {
+ menu.addAction(tr("Set as root"), this, [this, idx]() {
+ const auto path = model->filePath(idx);
+ qDebug() << "set root path" << path;
+ model->setRootPath(path);
+ setRootIndex(idx);
+ });
+ }
+ else {
+ menu.addAction(tr("Add to Playlist"), this, [this, idx]() {
+ const auto url = QUrl::fromLocalFile(model->filePath(idx));
+ emit addLocalFile(url);
+ });
+ }
+
+ menu.exec(mapToGlobal(pos));
+ }
+}
diff --git a/src/fsview.hpp b/src/fsview.hpp
new file mode 100644
index 0000000..eea61c7
--- /dev/null
+++ b/src/fsview.hpp
@@ -0,0 +1,30 @@
+/* ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#pragma once
+
+#include <QTreeView>
+#include <QUrl>
+
+class QFileSystemModel;
+class FSView : public QTreeView {
+ Q_OBJECT
+
+public:
+ FSView(QWidget *parent = nullptr);
+ ~FSView();
+
+signals:
+ void addLocalFile(const QUrl &url);
+
+public slots:
+ void setRootPath(const QString &path);
+
+private slots:
+ void contextMenu(const QPoint &pos);
+
+private:
+ QFileSystemModel *model;
+};
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..1fedca7
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,15 @@
+/* ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "maindialog.hpp"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainDialog w;
+ w.show();
+ return a.exec();
+}
diff --git a/src/maindialog.cpp b/src/maindialog.cpp
new file mode 100644
index 0000000..ee6fdd7
--- /dev/null
+++ b/src/maindialog.cpp
@@ -0,0 +1,44 @@
+/* ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "maindialog.hpp"
+#include "playlist.hpp"
+#include "playlistmodel.hpp"
+#include "ui_maindialog.h"
+#include <QAudioOutput>
+#include <QFileDialog>
+#include <QMediaPlayer>
+
+MainDialog::MainDialog(QWidget *parent)
+ : QDialog(parent), ui(new Ui::MainDialog),
+ m_playlist(new Playlist(this)), m_player{new QMediaPlayer(this)}, m_audioSink{new QAudioOutput(this)}
+{
+ m_player->setAudioOutput(m_audioSink);
+ m_audioSink->setVolume(50);
+
+ ui->setupUi(this);
+ ui->playlist->setModel(m_playlist->model());
+
+ connect(ui->fsSetRoot, &QPushButton::clicked, this, [this]() {
+ const auto root = QFileDialog::getExistingDirectory(this, tr("Set Root"), QDir::homePath());
+ if (!root.isEmpty()) ui->fsView->setRootPath(root);
+ });
+
+ connect(m_player, &QMediaPlayer::durationChanged, ui->progress, &QSlider::setMaximum);
+ connect(m_player, &QMediaPlayer::positionChanged, ui->progress, &QSlider::setValue);
+
+ connect(ui->fsView, &FSView::addLocalFile, m_playlist, &Playlist::appendUrl);
+ connect(ui->open, &QPushButton::clicked, this, [this]() {
+ const auto filelist = QFileDialog::getOpenFileUrls(this, tr("Open Files"));
+ m_playlist->appendList(filelist);
+ });
+ connect(ui->playlist, &QListView::activated, this, [this](const QModelIndex &index) {
+ const auto url = m_playlist->model()->data(index, Qt::DisplayRole).toUrl();
+ m_player->setSource(url);
+ m_player->play();
+ });
+}
+
+MainDialog::~MainDialog() { delete ui; }
diff --git a/src/maindialog.hpp b/src/maindialog.hpp
new file mode 100644
index 0000000..db22b2e
--- /dev/null
+++ b/src/maindialog.hpp
@@ -0,0 +1,29 @@
+/* ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2023 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#pragma once
+
+#include <QDialog>
+
+namespace Ui {
+class MainDialog;
+}
+class Playlist;
+class QMediaPlayer;
+class QAudioOutput;
+class MainDialog : public QDialog {
+ Q_OBJECT
+
+public:
+ MainDialog(QWidget *parent = nullptr);
+ ~MainDialog();
+
+private:
+ Ui::MainDialog *ui;
+ Playlist *m_playlist;
+
+ QMediaPlayer *m_player;
+ QAudioOutput *m_audioSink;
+};
diff --git a/src/maindialog.ui b/src/maindialog.ui
new file mode 100644
index 0000000..c2cb900
--- /dev/null
+++ b/src/maindialog.ui
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainDialog</class>
+ <widget class="QDialog" name="MainDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainDialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Tab 1</string>
+ </attribute>
+ </widget>
+ <widget class="QWidget" name="tab_2">
+ <attribute name="title">
+ <string>Tab 2</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QPushButton" name="fsSetRoot">
+ <property name="text">
+ <string>Set Root</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="FSView" name="fsView"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListView" name="playlist"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QSlider" name="progress">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="open">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="play">
+ <property name="text">
+ <string>Play</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stop">
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>FSView</class>
+ <extends>QTreeView</extends>
+ <header>src/fsview.hpp</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>