From b68f60e023175b144664de092c31416fa5b58880 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Tue, 19 Apr 2016 23:42:18 +0800 Subject: Fix argument parsing on Windows. --- qmidiplayer-desktop/main.cpp | 2 +- qmidiplayer-desktop/qmpmainwindow.cpp | 54 +++++++++++++++++++++++++---------- qmidiplayer-desktop/qmpmainwindow.hpp | 3 +- 3 files changed, 42 insertions(+), 17 deletions(-) (limited to 'qmidiplayer-desktop') diff --git a/qmidiplayer-desktop/main.cpp b/qmidiplayer-desktop/main.cpp index e763811..2ac275e 100644 --- a/qmidiplayer-desktop/main.cpp +++ b/qmidiplayer-desktop/main.cpp @@ -32,7 +32,7 @@ int main(int argc,char **argv) qmpTranslator.load("qmp_"+QLocale::system().name()); a.installTranslator(&qmpTranslator); qmpMainWindow w; - if(w.pharseArgs(argc,argv)==1)return 0; + if(w.pharseArgs()==1)return 0; w.init(); return a.exec(); diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp index 82537d2..e38ed2a 100644 --- a/qmidiplayer-desktop/qmpmainwindow.cpp +++ b/qmidiplayer-desktop/qmpmainwindow.cpp @@ -99,37 +99,60 @@ void qmpMainWindow::init() if(havemidi)on_pbPlayPause_clicked(); } -int qmpMainWindow::pharseArgs(int argc,char** argv) +int qmpMainWindow::pharseArgs() { bool loadfolder=false;havemidi=false; - for(int i=1;iemptyList();} + if(loadfolder||qmpSettingsWindow::getSettingsIntf()->value("Behavior/LoadFolder",0).toInt()) + { + QDirIterator di(QFileInfo(args.at(i)).absolutePath()); + while(di.hasNext()) + { + QString c=di.next();char* cc=wcsto8bit(c.toStdWString().c_str()); + if((c.endsWith(".mid")||c.endsWith(".midi"))&&fluid_is_midifile(cc)) + plistw->insertItem(c);free(cc); + } + } + else + plistw->insertItem(args.at(i)); + } + free(c); + } +#else + if(fluid_is_midifile(args.at(i).toStdString().c_str())) { if(!havemidi){havemidi=true;plistw->emptyList();} if(loadfolder||qmpSettingsWindow::getSettingsIntf()->value("Behavior/LoadFolder",0).toInt()) { - QDirIterator di(QFileInfo(argv[i]).absolutePath()); + QDirIterator di(QFileInfo(args.at(i)).absolutePath()); while(di.hasNext()) { QString c=di.next(); @@ -138,8 +161,9 @@ int qmpMainWindow::pharseArgs(int argc,char** argv) } } else - plistw->insertItem(argv[i]); + plistw->insertItem(args.at(i).toStdString().c_str()); } +#endif } return 0; } @@ -206,7 +230,7 @@ void qmpMainWindow::updateWidgets() if(singleFS)player->playerPanic(true); chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getNextItem(); - ui->lbFileName->setText(QUrl(fns).fileName()); + ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName()); LOAD_FILE; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); @@ -306,7 +330,7 @@ void qmpMainWindow::on_pbPlayPause_clicked() fns=plistw->getFirstItem(); if(!fns.length())return(void)(playing=false); } - ui->lbFileName->setText(QUrl(fns).fileName()); + ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName()); LOAD_FILE; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); @@ -430,7 +454,7 @@ void qmpMainWindow::on_pbPrev_clicked() if(singleFS)player->playerPanic(true); ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getPrevItem();if(fns.length()==0)return on_pbStop_clicked(); - ui->lbFileName->setText(QUrl(fns).fileName()); + ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName()); LOAD_FILE; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); @@ -455,7 +479,7 @@ void qmpMainWindow::on_pbNext_clicked() if(singleFS)player->playerPanic(true); ui->hsTimer->setValue(0);chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getNextItem();if(fns.length()==0)return on_pbStop_clicked(); - ui->lbFileName->setText(QUrl(fns).fileName()); + ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName()); LOAD_FILE; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); @@ -483,7 +507,7 @@ void qmpMainWindow::selectionChanged() ui->hsTimer->setValue(0); chnlw->on_pbUnmute_clicked();chnlw->on_pbUnsolo_clicked(); QString fns=plistw->getSelectedItem(); - ui->lbFileName->setText(QUrl(fns).fileName()); + ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName()); LOAD_FILE; char ts[100]; sprintf(ts,"%02d:%02d",(int)player->getFtime()/60,(int)player->getFtime()%60); diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp index 729eb7f..55e0b12 100644 --- a/qmidiplayer-desktop/qmpmainwindow.hpp +++ b/qmidiplayer-desktop/qmpmainwindow.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "../core/qmpmidiplay.hpp" @@ -39,7 +40,7 @@ class qmpMainWindow:public QMainWindow QTimer* getTimer(){return timer;} bool isFinalizing(){return fin;} QString getFileName(); - int pharseArgs(int argc,char** argv); + int pharseArgs(); private slots: void on_pbPlayPause_clicked(); -- cgit v1.2.3