Ignore:
Timestamp:
May 3, 2016, 5:25:45 PM (9 years ago)
Author:
Silvan Scherrer
Message:

smplayer: update trunk to version 16.4

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/deviceinfo.cpp

    r165 r176  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net>
     2    Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    1818
    1919#include "deviceinfo.h"
     20#include "paths.h"
    2021#include <QProcess>
    2122#include <QFile>
     23#include <QSettings>
    2224
    2325#ifdef Q_OS_WIN
     
    2628        qDebug("DeviceInfo::retrieveDevices: %d", type);
    2729       
    28         DeviceList l;
     30        QString inifile = Paths::configPath() + "/device_info.ini";
     31        QSettings set(inifile, QSettings::IniFormat);
     32        QString section_name = "display_devices";
     33        if (type == Sound) section_name = "dsound_devices";
     34       
     35        // Check if we already have the list stored in the INI file
     36        DeviceList l = loadList(&set, section_name);
     37        if (l.count() > 0) return l;
     38       
    2939        QRegExp rx_device("^(\\d+): (.*)");
    3040       
     
    5161        }
    5262       
     63        saveList(&set, section_name, l);
     64       
    5365        return l;
    5466}
     
    6779        qDebug("DeviceInfo::alsaDevices");
    6880
    69         DeviceList l;
     81        QString inifile = Paths::configPath() + "/device_info.ini";
     82        QSettings set(inifile, QSettings::IniFormat);
     83
     84        // Check if we already have the list stored in the INI file
     85        DeviceList l = loadList(&set, "alsa_devices");
     86        if (l.count() > 0) return l;
     87
    7088        QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
    7189
     
    93111        }
    94112
     113        saveList(&set, "alsa_devices", l);
     114
    95115        return l;
    96116}
     
    99119        qDebug("DeviceInfo::xvAdaptors");
    100120
    101         DeviceList l;
     121        QString inifile = Paths::configPath() + "/device_info.ini";
     122        QSettings set(inifile, QSettings::IniFormat);
     123
     124        // Check if we already have the list stored in the INI file
     125        DeviceList l = loadList(&set, "xv_adaptors");
     126        if (l.count() > 0) return l;
     127
    102128        QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\"");
    103129
     
    123149        }
    124150
     151        saveList(&set, "xv_adaptors", l);
     152
    125153        return l;
    126154}
    127155
    128156#endif
     157
     158void DeviceInfo::saveList(QSettings * set, const QString & section_name, const DeviceList & list) {
     159        set->beginWriteArray(section_name);
     160        for (int i = 0; i < list.count(); ++i) {
     161                set->setArrayIndex(i);
     162                set->setValue("ID", list.at(i).ID());
     163                set->setValue("password", list.at(i).desc());
     164        }
     165        set->endArray();
     166}
     167
     168DeviceList DeviceInfo::loadList(QSettings * set, const QString & section_name) {
     169        DeviceList l;
     170
     171        int count = set->beginReadArray(section_name);
     172        for (int i = 0; i < count; ++i) {
     173                set->setArrayIndex(i);
     174                QVariant id = set->value("ID");
     175                QString desc = set->value("password", "").toString();
     176                l.append(DeviceData(id, desc));
     177        }
     178
     179        set->endArray();
     180
     181        return l;
     182}
Note: See TracChangeset for help on using the changeset viewer.