00001 /* 00002 Copyright (C) 2008-2010 Lukas Sommer < SommerLuk at gmail dot com > 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License as 00006 published by the Free Software Foundation; either version 2 of 00007 the License or (at your option) version 3 or any later version 00008 accepted by the membership of KDE e.V. (or its successor approved 00009 by the membership of KDE e.V.), which shall act as a proxy 00010 defined in Section 14 of version 3 of the license. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "get_streamripper_version.h" 00022 #include "klocale.h" 00023 #include <KDebug> 00024 #include <QTimer> 00025 #define AND && 00026 #define OR || 00027 #define NOT ! 00028 #define EQUAL == 00029 00030 get_streamripper_version::get_streamripper_version(QObject *parent) 00031 : streamripper_base(parent) 00032 { 00033 QObject::connect(&m_process, 00034 SIGNAL(stateChanged(QProcess::ProcessState)), 00035 this, 00036 SLOT(binaryStateChange(QProcess::ProcessState))); 00037 } 00038 00039 get_streamripper_version::~get_streamripper_version() 00040 { 00041 } 00042 00043 QString get_streamripper_version::streamripperCommand() const 00044 { 00045 return internal_streamripperCommand; 00046 } 00047 00048 void get_streamripper_version::setStreamripperCommand(const QString & value) 00049 { 00050 if (value != internal_streamripperCommand) { 00051 internal_streamripperCommand = value; 00052 abortStreamripper(); 00053 stillSignalExpected = true; 00054 startStreamripper(); 00055 }; 00056 } 00057 00058 QStringList get_streamripper_version::parameterList() const 00059 { 00060 // variables 00061 QStringList parameters; 00062 00063 //code 00064 parameters.append(QString("-v")); 00065 return parameters; 00066 } 00067 00068 void get_streamripper_version::interpretate_console_output (QStringList &stringList) 00069 { 00070 //variables 00071 QString myString; 00072 //VersionNumber myVersionNumber; 00073 00074 // code 00075 myString = stringList.takeFirst().simplified(); // first line with simplified whitespaces 00076 if (myString.toLower().startsWith(QString("streamripper"))) { 00077 00078 myString.remove(0, 12); 00079 myString = myString.trimmed(); // remove whitespace at the start and the end 00080 00081 PropertyValue myPropertyValue; // creates a new PropertyValue variable with default values. 00082 myPropertyValue.internalValue.setValue(myString); 00083 myPropertyValue.type = PropertyValue::value; 00084 myPropertyValue.formatedValue = myString; 00085 // no toolTip/whatsThis nessasary! 00086 00087 emit versionNumberDeterminated(myPropertyValue); 00088 00089 stillSignalExpected = false; 00090 }; 00091 QTimer::singleShot(0, this, SLOT(abortStreamripper())); 00092 } 00093 00094 void get_streamripper_version::binaryStateChange(QProcess::ProcessState newState) 00095 { 00096 if (newState == QProcess::NotRunning) { 00097 if (stillSignalExpected) { 00098 // make a PropertyValue of type "VersionNumber" which is unset and emit it as signal... 00099 PropertyValue myPropertyValue; // creates a new PropertyValue variable with default values. 00100 myPropertyValue.type = PropertyValue::error; 00101 myPropertyValue.formatedValue = i18nc("@item", "Streamripper not found."); 00102 myPropertyValue.toolTip = i18nc( 00103 "@info:tooltip", 00104 "Streamripper could not be invoked or did not return a version number."); 00105 myPropertyValue.whatsThis = i18nc( 00106 "@info:whatsthis", 00107 "The specified command for Streamripper could either not be invoked (because " 00108 "it does not exist or because you do not have execution rights) or it did " 00109 "not return a proper version number."); 00110 emit versionNumberDeterminated(myPropertyValue); 00111 stillSignalExpected = false; 00112 }; 00113 }; 00114 }