A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 157 lines 4.6 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2010 Robert Bieber 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21 22#include "newprojectdialog.h" 23#include "ui_newprojectdialog.h" 24#include "targetdata.h" 25 26#include <QSettings> 27#include <QFileDialog> 28#include <QDir> 29 30NewProjectDialog::NewProjectDialog(QWidget *parent) : 31 QDialog(parent), 32 ui(new Ui::NewProjectDialog) 33{ 34 ui->setupUi(this); 35 36 /* Getting the default directory from the application settings */ 37 QSettings settings; 38 settings.beginGroup("NewProjectDialog"); 39 40 ui->locationBox->setText(settings.value("defaultDir", 41 QDir::home().absolutePath()) 42 .toString()); 43 44 settings.endGroup(); 45 46 /* Populating the target box */ 47 TargetData targets; 48 for(int i = 0; i < targets.count(); i++) 49 { 50 ui->targetBox->insertItem(i, QIcon(), targets.name(i), targets.id(i)); 51 } 52 targetChange(0); 53 54 /* Connecting the browse button and target box */ 55 QObject::connect(ui->browseButton, SIGNAL(clicked()), 56 this, SLOT(browse())); 57 QObject::connect(ui->targetBox, SIGNAL(currentIndexChanged(int)), 58 this, SLOT(targetChange(int))); 59} 60 61NewProjectDialog::~NewProjectDialog() 62{ 63 delete ui; 64} 65 66void NewProjectDialog::accept() 67{ 68 status.name = ui->nameBox->text(); 69 status.path = ui->locationBox->text(); 70 status.target = ui->targetBox->itemData(ui->targetBox->currentIndex()) 71 .toString(); 72 status.sbs = ui->sbsBox->isChecked(); 73 status.wps = ui->wpsBox->isChecked(); 74 status.fms = ui->fmsBox->isChecked(); 75 status.rsbs = ui->rsbsBox->isChecked(); 76 status.rwps = ui->rwpsBox->isChecked(); 77 status.rfms = ui->rfmsBox->isChecked(); 78 79 QSettings settings; 80 settings.beginGroup("NewProjectDialog"); 81 82 settings.setValue("defaultDir", ui->locationBox->text()); 83 84 settings.endGroup(); 85 86 QDialog::accept(); 87} 88 89void NewProjectDialog::reject() 90{ 91 ui->nameBox->setText(status.name); 92 ui->locationBox->setText(status.path); 93 ui->targetBox->setCurrentIndex(0); 94 ui->sbsBox->setChecked(status.sbs); 95 ui->wpsBox->setChecked(status.wps); 96 ui->fmsBox->setChecked(status.fms); 97 ui->rsbsBox->setChecked(status.rsbs); 98 ui->rwpsBox->setChecked(status.rwps); 99 ui->rfmsBox->setChecked(status.rfms); 100 101 QSettings settings; 102 settings.beginGroup("NewProjectDialog"); 103 104 ui->locationBox->setText(settings.value("defaultDir", 105 QDir::home().absolutePath()) 106 .toString()); 107 108 settings.endGroup(); 109 110 QDialog::reject(); 111} 112 113void NewProjectDialog::browse() 114{ 115 QString path; 116 path = QFileDialog::getExistingDirectory(this, "New Project Location", 117 ui->locationBox->text()); 118 ui->locationBox->setText(path); 119} 120 121void NewProjectDialog::targetChange(int target) 122{ 123 TargetData targets; 124 125 if(targets.fm(target)) 126 { 127 ui->fmsBox->setEnabled(true); 128 ui->rfmsBox->setEnabled(true); 129 } 130 else 131 { 132 ui->fmsBox->setChecked(false); 133 ui->rfmsBox->setChecked(false); 134 135 ui->fmsBox->setEnabled(false); 136 ui->rfmsBox->setEnabled(false); 137 } 138 139 if(targets.remoteDepth(target) == TargetData::None) 140 { 141 ui->rwpsBox->setChecked(false); 142 ui->rsbsBox->setChecked(false); 143 ui->rfmsBox->setChecked(false); 144 145 ui->rsbsBox->setEnabled(false); 146 ui->rwpsBox->setEnabled(false); 147 ui->rfmsBox->setEnabled(false); 148 } 149 else 150 { 151 ui->rsbsBox->setEnabled(true); 152 ui->rwpsBox->setEnabled(true); 153 if(targets.fm(target)) 154 ui->rfmsBox->setEnabled(true); 155 } 156 157}