Changeset 25


Ignore:
Timestamp:
12/31/07 15:06:00 (4 years ago)
Author:
sander
Message:

Preferences dialog is now functional and pops up when no connection can be made

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • QtMPC.pro

    r24 r25  
    99CONFIG += qt debug 
    1010QT += network 
    11 #DEFINES += QT_NO_DEBUG_OUTPUT 
     11DEFINES += QT_NO_DEBUG_OUTPUT 
    1212 
    1313# Input 
  • gui/main_window.cpp

    r19 r25  
    11#include <cmath> 
    22#include <QtGui> 
     3 
    34#include "main_window.h" 
     5#include "preferences_dialog.h" 
    46 
    57MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) 
    68{ 
     9    QSettings settings; 
     10 
    711    setupUi(this); 
    812 
    9     //mpd_status = NULL; 
    1013    slidingVolume = false; 
    1114 
     15    // Start connection thread 
    1216    mpd.start(); 
    13     mpd.setHostname("mediapc"); 
    14     mpd.setPort(6600); 
    15     if(!mpd.connectToMPD()) { 
    16         qDebug("Big trouble! Exiting..."); 
    17         qApp->quit(); 
     17 
     18    // Set connection data 
     19    mpd.setHostname(settings.value("connection/host").toString()); 
     20    mpd.setPort(settings.value("connection/port").toInt()); 
     21 
     22    while(!mpd.connectToMPD()) { 
     23        showPreferencesDialog(); 
     24 
     25        mpd.setHostname(settings.value("connection/host").toString()); 
     26        mpd.setPort(settings.value("connection/port").toInt()); 
    1827    } 
    1928 
     
    3342 
    3443    // GUI 
     44    connect(action_Preferences, SIGNAL(triggered(bool)), this, SLOT(showPreferencesDialog())); 
    3545    connect(volumeSlider, SIGNAL(sliderPressed()), this, SLOT(volumeSliderPressed())); 
    3646    connect(volumeSlider, SIGNAL(sliderReleased()), this, SLOT(setVolume())); 
     
    5868}*/ 
    5969 
     70void MainWindow::showPreferencesDialog() 
     71{ 
     72    PreferencesDialog pref(this); 
     73    pref.exec(); 
     74} 
     75 
    6076void MainWindow::volumeSliderPressed() 
    6177{ 
     
    210226    QModelIndex mappedIndex = libraryProxyModel.mapToSource(index); 
    211227    item = static_cast<MusicLibraryItem *>(mappedIndex.internalPointer()); 
     228    MPDStatus::State curState = mpd_status.state; 
    212229 
    213230    switch(item->type()) { 
     
    232249    if(!files.isEmpty()) { 
    233250        mpd.add(files); 
    234         mpd.startPlayingSong(); 
    235     } 
    236 } 
     251        if(curState != MPDStatus::State_Playing) 
     252            mpd.startPlayingSong(); 
     253    } 
     254} 
  • gui/main_window.h

    r19 r25  
    3030 
    3131    private slots: 
     32        void showPreferencesDialog(); 
    3233        void volumeSliderPressed(); 
    3334        void volumeSliderReleased(); 
  • gui/preferences_dialog.cpp

    r23 r25  
    33PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) 
    44{ 
    5     //loadSettings(); 
     5    setupUi(this); 
     6 
     7    connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonPressed(QAbstractButton *))); 
     8 
     9    loadSettings(); 
    610} 
    711 
     
    913{ 
    1014    hostLineEdit->setText(settings.value("connection/host", "").toString()); 
    11     portSpinBox->setValue(settings.value("connection/port", 6600).toInt()); 
     15    portSpinBox->setValue(settings.value("connection/port").toInt()); 
     16    passwordLineEdit->setText(settings.value("connection/password", "").toString()); 
    1217} 
    1318 
     
    1520{ 
    1621} 
     22 
     23void PreferencesDialog::buttonPressed(QAbstractButton *button) 
     24{ 
     25    switch(buttonBox->buttonRole(button)) { 
     26        case QDialogButtonBox::AcceptRole: 
     27        case QDialogButtonBox::ApplyRole: 
     28            settings.setValue("connection/host", hostLineEdit->text()); 
     29            settings.setValue("connection/port", portSpinBox->value()); 
     30            settings.setValue("connection/password", passwordLineEdit->text()); 
     31            break; 
     32        case QDialogButtonBox::RejectRole: 
     33            break; 
     34        default: 
     35            /* unhandled button */ 
     36            break; 
     37    } 
     38} 
  • gui/preferences_dialog.h

    r23 r25  
    1212 
    1313    public: 
    14         PreferencesDialog(QWidget * parent = 0, Qt::WindowFlags f = 0); 
     14        PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); 
    1515 
    1616    private: 
     
    2020        void loadSettings(); 
    2121        void writeSettings(); 
     22        void buttonPressed(QAbstractButton *button); 
    2223}; 
    2324 
  • lib/mpdparseutils.cpp

    r19 r25  
    7979                if(j != 1 && j != tokens.size() - 1) 
    8080                    song->album += ":"; 
    81                 song->album += tokens.at(j); 
     81                song->album += QString::fromUtf8(tokens.at(j)); 
    8282            } 
    8383        } else if(tokens.at(0) == "Artist") { 
     
    8585                if(j != 1 && j != tokens.size() - 1) 
    8686                    song->artist += ":"; 
    87                 song->artist += tokens.at(j); 
     87                song->artist += QString::fromUtf8(tokens.at(j)); 
    8888            } 
    8989        } else if(tokens.at(0) == "Title") { 
     
    9191                if(j != 1 && j != tokens.size() - 1) 
    9292                    song->title += ":"; 
    93                 song->title += tokens.at(j); 
     93                song->title += QString::fromUtf8(tokens.at(j)); 
    9494            } 
    9595        } else if(tokens.at(0) == "Track") { 
  • main.cpp

    r8 r25  
    77    QApplication app(argc, argv); 
    88    QApplication::setApplicationName("qtmpc"); 
     9    QApplication::setOrganizationName("lowblogprojects"); 
    910 
    1011    MainWindow w; 
Note: See TracChangeset for help on using the changeset viewer.