1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

SoundPlayer: Let the user open a file from the GUI

The user now can open a file without passing it as an argument
This commit is contained in:
Till Mayer 2019-11-09 17:15:16 +01:00 committed by Andreas Kling
parent b7efebe11c
commit 56cd8b4d17
5 changed files with 123 additions and 66 deletions

View file

@ -1,58 +1,59 @@
#include "SoundPlayerWidget.h"
#include <AK/StringBuilder.h>
#include <LibAudio/ABuffer.h>
#include <LibAudio/AClientConnection.h>
#include <LibAudio/AWavLoader.h>
#include <LibCore/CTimer.h>
#include <LibDraw/CharacterBitmap.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GFilePicker.h>
#include <LibGUI/GMenu.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GSlider.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>
#include <LibGUI/GAboutDialog.h>
#include <stdio.h>
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: %s <wav-file>\n", argv[0]);
return 0;
}
GApplication app(argc, argv);
String path = argv[1];
AWavLoader loader(path);
if (loader.has_error()) {
fprintf(stderr, "Failed to load WAV file: %s (%s)\n", path.characters(), loader.error_string());
return 1;
}
auto audio_client = AClientConnection::construct();
audio_client->handshake();
auto app_menu = make<GMenu>("SoundPlayer");
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
app.quit();
}));
auto menubar = make<GMenuBar>();
menubar->add_menu(move(app_menu));
app.set_menubar(move(menubar));
auto window = GWindow::construct();
window->set_title("SoundPlayer");
window->set_resizable(false);
window->set_rect(300, 300, 350, 140);
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/app-sound-player.png"));
auto player = SoundPlayerWidget::construct(window, audio_client, loader);
auto menubar = make<GMenuBar>();
auto app_menu = make<GMenu>("SoundPlayer");
auto player = SoundPlayerWidget::construct(window, audio_client);
if (argc > 1) {
String path = argv[1];
player->open_file(path);
player->manager().play();
}
app_menu->add_action(GCommonActions::make_open_action([&](auto&) {
Optional<String> path = GFilePicker::get_open_filepath("Open wav file...");
if (path.has_value()) {
player->open_file(path.value());
}
}));
app_menu->add_separator();
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
app.quit();
}));
menubar->add_menu(move(app_menu));
auto help_menu = make<GMenu>("Help");
help_menu->add_action(GAction::create("About", [](auto&) {
GAboutDialog::show("SoundPlayer", GraphicsBitmap::load_from_file("/res/icons/32x32/app-sound-player.png"));
}));
menubar->add_menu(move(help_menu));
app.set_menubar(move(menubar));
window->set_main_widget(player);
window->show();