A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 133 lines 3.8 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 23#include "projectmodel.h" 24#include "editorwindow.h" 25 26#include <QFile> 27#include <QTextStream> 28#include <QMap> 29#include <QDir> 30 31ProjectModel::ProjectModel(QString config, EditorWindow* mainWindow, 32 QObject *parent) 33 : QAbstractListModel(parent), 34 mainWindow(mainWindow) 35{ 36 /* Reading the config file */ 37 QFile cfg(config); 38 cfg.open(QFile::ReadOnly | QFile::Text); 39 if(!cfg.isReadable()) 40 return; 41 42 settings.insert("configfile", config); 43 44 QTextStream fin(&cfg); 45 46 /* Storing the base directory */ 47 QString confDir = config; 48 confDir.chop(confDir.length() - confDir.lastIndexOf('/') - 1); 49 QDir base(confDir); 50 base.cdUp(); 51 settings.insert("themebase", base.canonicalPath()); 52 53 while(!fin.atEnd()) 54 { 55 QString current = fin.readLine(); 56 QList<QString> parts = current.split(':'); 57 58 /* A valid setting has at least one : */ 59 if(parts.count() < 2) 60 continue; 61 62 QString setting; 63 for(int i = 1; i < parts.count(); i++) 64 setting.append(parts[i].trimmed()); 65 66 settings.insert(parts[0].trimmed(), setting); 67 } 68 69 cfg.close(); 70 71 /* Adding the files, starting with the .cfg */ 72 config.replace(base.canonicalPath() + "/", ""); 73 files.append(config); 74 75 QList<QString> keys; 76 keys.append("wps"); 77 keys.append("rwps"); 78 keys.append("sbs"); 79 keys.append("rsbs"); 80 keys.append("fms"); 81 keys.append("rfms"); 82 83 for(int i = 0; i < keys.count(); i++) 84 { 85 QString file = settings.value(keys[i], ""); 86 if(file != "" && file != "-") 87 { 88 file.replace("/.rockbox/", ""); 89 files.append(file); 90 } 91 } 92 93 94} 95 96ProjectModel::~ProjectModel() 97{ 98} 99 100int ProjectModel::rowCount(const QModelIndex& parent) const 101{ 102 return files.count(); 103} 104 105QVariant ProjectModel::data(const QModelIndex &index, int role) const 106{ 107 if(!index.isValid()) 108 return QVariant(); 109 110 if(role != Qt::DisplayRole) 111 return QVariant(); 112 113 return files[index.row()]; 114} 115 116void ProjectModel::activated(const QModelIndex &index) 117{ 118 if(index.row() == 0) 119 { 120 ConfigDocument* doc = new ConfigDocument(settings, 121 settings.value("themebase", 122 "") + "/" + 123 files[index.row()]); 124 QObject::connect(doc, SIGNAL(configFileChanged(QString)), 125 mainWindow, SLOT(configFileChanged(QString))); 126 mainWindow->loadConfigTab(doc); 127 } 128 else 129 { 130 mainWindow->loadTabFromSkinFile(settings.value("themebase", "") 131 + "/" + files[index.row()]); 132 } 133}