Exemple #1
0
App::App(int &argc, char **argv)
    : QApplication(argc, argv)
    , _invocation(argv[0])
    , _gui(false)
    , _interactive(false)
{
    // Enforce singleton property
    if (_instance) {
        throw std::runtime_error("Only one instance of App allowed.");
    }

    // Remember if we are done
    bool done = false;

    // Set the singleton instance to this
    _instance = this;

    // Set the application properties
    setApplicationName(APPLICATION_NAME);
    setApplicationVersion(APPLICATION_VERSION_STRING);
    setOrganizationName(APPLICATION_VENDOR_NAME);
    setOrganizationDomain(APPLICATION_VENDOR_URL);

    // Configure the logging mechanism
    log4cxx::LoggerPtr rootlogger = log4cxx::Logger::getRootLogger();
    rootlogger->addAppender(new log4cxx::ConsoleAppender(new log4cxx::PatternLayout("[%-5p] %m%n")));

    // Parse the commandline
    int idx = 1;
    while (idx < argc) {
        QString arg(argv[idx]);
        if (matches_option(arg, "help", 0) || matches_option(arg, "h") || matches_option(arg, "?", 0)) {
            printHelpMessage();
            std::exit(0);
        } else if (matches_option(arg, "version", 0)) {
            printVersionMessage();
            std::exit(0);
        } else if (matches_option(arg, "version-triplet")) {
            printVersionTripletMessage();
            std::exit(0);
        } else if (matches_option(arg, "prefset")) {
            // Verify that there is another argument
            if ((idx + 1) >= argc) {
                LOG4CXX_FATAL(_logger, "Option \"" << arg << "\" requires a parameter.");
                std::exit(1);
            }

            // Increment the index
            idx++;

            // Get the next parameter
            std::string param(argv[idx]);

            // Determine if there is an equals sign
            // If there is, set the preference;
            // Otherwise, remove the preference
            size_t eqidx = param.find('=');
            if (eqidx != std::string::npos) {
                std::string key = param.substr(0, eqidx);
                std::string val = param.substr(eqidx + 1);
                setPreference(key, val);
            } else {
                unsetPreference(param);
            }
            done = true;
        } else if (matches_option(arg, "prefdel")) {
            // Verify that there is another argument
            if ((idx + 1) >= argc) {
                LOG4CXX_FATAL(_logger, "Option \"" << arg << "\" requires a parameter.");
                std::exit(1);
            }

            // Increment the index
            idx++;

            // Get the next parameter
            std::string param(argv[idx]);

            // Remove the preference
            unsetPreference(param);
            done = true;
        } else if (matches_option(arg, "preflist")) {
            printAllPreferences();
            done = true;
        } else if (matches_option(arg, "prefget")) {
            // Verify that there is another argument
            if ((idx + 1) >= argc) {
                LOG4CXX_FATAL(_logger, "Option \"" << arg << "\" requires a parameter.");
                std::exit(1);
            }

            // Increment the index
            idx++;

            // Get the next parameter
            std::string param(argv[idx]);

            // Print the preference
            printPreference(param);
            done = true;
        } else if (matches_option(arg, "loglevel")) {
            // Verify that there is another argument
            if ((idx + 1) >= argc) {
                LOG4CXX_FATAL(_logger, "Option \"" << arg << "\" requires a parameter.");
                std::exit(1);
            }

            // Increment the index
            idx++;

            // Get the next parameter
            std::string param(argv[idx]);

            // Determine if there is an equals sign and act accordingly
            size_t eqidx = param.find('=');
            if (eqidx != std::string::npos) {
                std::string logger = param.substr(0, eqidx);
                std::string level  = param.substr(eqidx + 1);
                setLogLevel(logger, level);
            } else {
                setLogLevel("", param);
            }
        } else if (matches_option(arg, "appid") || matches_option(arg, "application-identifier")) {
            printApplicationIdentifier();
            std::exit(0);
        } else if (matches_option(arg, "gui")) {
            if (_interactive) {
                LOG4CXX_FATAL(_logger, "Cannot specify both \"--gui\" and \"--interactive\" simultaneously.");
                std::exit(1);
            }
            if (_gui) {
                LOG4CXX_WARN(_logger, "Option \"" << arg << "\" already specified. Ignoring.");
            }
            _gui = true;
        } else if (matches_option(arg, "interactive")) {
            if (_gui) {
                LOG4CXX_FATAL(_logger, "Cannot specify both \"--gui\" and \"--interactive\" simultaneously.");
                std::exit(1);
            }
            if (_interactive) {
                LOG4CXX_WARN(_logger, "Option \"" << arg << "\" already specified. Ignoring.");
            }
            _interactive = true;
        } else {
            LOG4CXX_WARN(_logger, "Unrecognized option: \"" << arg << "\". Ignoring");
        }
        idx++;
    }

    initGUI();
}
void PhononItem::metaStateChanged(Phonon::State newState, Phonon::State oldState) {
    Q_UNUSED(oldState);
  //  static QObjectWriter writer(this, false);

    if (newState == Phonon::ErrorState) {
        qDebug() << "PhononItem: Error Opening File: " << fileName();

        emit fetched(false);
        return;
    }

    if (m_metaMedia->currentSource().type() == Phonon::MediaSource::Invalid) {

        emit fetched(false);
        qDebug() << "Invalid metadata: " << fileName();
        return;
    }

    QMap<QString, QString> metaData = m_metaMedia->metaData();

    setArtist(metaData.value("ARTIST"));
    setTrackTitle(metaData.value("TITLE"));
    setAlbumTitle(metaData.value("ALBUM"));
    setGenre(metaData.value("GENRE"));
    QString tn = metaData.value("TRACK-NUMBER");
    if (tn == QString()) tn = metaData.value("TRACKNUMBER");
    setTrackNumber(tn);
    extendedComment = QString();
    QString comment =  metaData.value("COMMENT");
    setComment(comment);
    
    // http://www.freedesktop.org/wiki/Specifications/free-media-player-specs
    QString fmpsRating = metaData.value("FMPS_Rating");
    // ??? Why does this not work?
    if (fmpsRating.toDouble() > 0 ) {
        int stars = fmpsRating.toDouble() * 10;
        Preference fmpsPref(stars);
        qDebug() << "FMPS Rating: " << stars;
        setPreference(fmpsPref);
    }

    // Preference can be obtained from various ways.
    else setPreference(comment);

    // Check for MusicMatch preference
    if ((preference().intValue() == 0) && metaData.contains("EXTENDED-COMMENT")) {
        extendedComment = metaData.value("EXTENDED-COMMENT");
        int eqidx = extendedComment.indexOf("=");
        if (eqidx > 0)
            extendedComment=extendedComment.mid(eqidx+1);
        Preference p(extendedComment);
        if (p.intValue() > 0) {
            setPreference(p);
            setComment(p.toString());
        }
    }

//start id="notify"
    m_loaded = true;
    if (m_timeSet) {
        emit fetched();
    }
//end

}