Пример #1
0
void SatellitesPlugin::initialize()
{
    // FIXME: remove the const_cast, it may be best to create a new type of
    // plugins where marbleModel() is not const, since traditional
    // RenderPlugins do not require that
    m_satModel = new SatellitesModel(
        const_cast<MarbleModel *>( marbleModel() )->treeModel(),
        marbleModel()->clock() );

    m_configModel = new SatellitesConfigModel( this );
    m_configDialog->configWidget()->treeView->setModel( m_configModel );

    connect( m_satModel, SIGNAL(fileParsed(QString)),
        SLOT(dataSourceParsed(QString)) );
    connect( m_satModel, SIGNAL(fileParsed(QString)),
        SLOT(updateDataSourceConfig(QString)) );
    connect( m_configDialog, SIGNAL(dataSourcesReloadRequested()),
        SLOT(updateSettings()) );
    connect( m_configDialog, SIGNAL(accepted()), SLOT(writeSettings()) );
    connect( m_configDialog, SIGNAL(rejected()), SLOT(readSettings()) );
    connect( m_configDialog->configWidget()->buttonBox->button(
        QDialogButtonBox::Reset ),
        SIGNAL(clicked()), SLOT(restoreDefaultSettings()) );
    connect( m_configDialog, SIGNAL(userDataSourcesChanged()),
        SLOT(writeSettings()) );
    connect( m_configDialog, SIGNAL(userDataSourceAdded(QString)),
        SLOT(userDataSourceAdded(QString)) );

    m_isInitialized = true;
    readSettings();
    updateSettings();
    enableModel( enabled() );
}
Пример #2
0
void SatellitesConfigDialog::openDataSource()
{
    QListWidget *list = m_configWidget->listDataSources;

    const QString filter = QString("%1;;%2;;%3").arg(
        tr( "All Supported Files (*.txt *.msc)" ),
        tr( "Marble Satellite Catalogue (*.msc)" ),
        tr( "Two Line Element Set (*.txt)" ),
        tr( "All Files (*.*)" ) );

    QString filename = QFileDialog::getOpenFileName( this,
        tr( "Open Satellite Data File" ), "", filter );

    if( !filename.isNull() ) {
        QString url = QUrl::fromLocalFile( filename ).toString();

        if( m_configWidget->listDataSources->findItems(
                url, Qt::MatchFixedString ).size() > 0 ) {
            mDebug() << "Satellite data source exists:" << url;
            return; // already in list
        }

        QListWidgetItem *item = new QListWidgetItem( url, list );
        item->setFlags( Qt::ItemIsSelectable |
                        Qt::ItemIsEnabled );
        item->setData( IsLoadedRole, QVariant( false ) );

        mDebug() << "Added satellite data source:" << url;
        m_userDataSources << url;

        emit userDataSourceAdded( url );
        emit userDataSourcesChanged();
    }

}
Пример #3
0
void SatellitesConfigDialog::addDataSource()
{
    QListWidget *list = m_configWidget->listDataSources;

    bool ok;
    QString text = QInputDialog::getText( this,
                                          tr("Add Data Source"),
                                          tr("URL or File path:"),
                                          QLineEdit::Normal,
                                          "", &ok);

    if( ok && !text.isEmpty() ) {
        QUrl url = QUrl::fromUserInput( text );
        if( !url.isValid() ) {
            mDebug() << "Invalid data source input:" << text;
            QMessageBox::critical( this,
                                   tr( "Invalid data source input" ),
                                   tr( "Please enter a valid URL or file path!" ),
                                   QMessageBox::Cancel );
            return;
        }

        // add item
        QListWidgetItem *item = new QListWidgetItem( url.toString(), list );
        item->setFlags( Qt::ItemIsSelectable |
                        Qt::ItemIsEnabled );
        item->setData( IsLoadedRole, QVariant( false ) );

        mDebug() << "Added satellite data source:" << item->text();
        m_userDataSources << item->text();

        emit userDataSourceAdded( item->text() );
        emit userDataSourcesChanged();
    }
}
Пример #4
0
void SatellitesPlugin::setSettings( const QHash<QString, QVariant> &settings )
{
    RenderPlugin::setSettings( settings );

    // add default data sources
    if( !settings.contains( "dataSources" ) ) {
        QStringList dsList;
        dsList << "http://www.celestrak.com/NORAD/elements/visual.txt";
        m_settings.insert( "dataSources", dsList );
        m_settings.insert( "idList", dsList );
    }
    else {
        // HACK: KConfig can't guess the type of the settings, when we use
        // KConfigGroup::readEntry() in marble_part it returns a QString which
        // is then wrapped into a QVariant when added to the settings hash.
        // QVariant can handle the conversion for some types, like toDateTime()
        // but when calling toStringList() on a QVariant::String, it will
        // return a one element list
        if( settings.value( "dataSources" ).type() == QVariant::String ) {
            m_settings.insert( "dataSources",
                settings.value( "dataSources" ).toString().split(QLatin1Char( ',' ) ) );
        }
        if( settings.value( "idList" ).type() == QVariant::String ) {
            m_settings.insert( "idList",
                settings.value( "idList" ).toString().split(QLatin1Char( ',' ) ) );
        }
    }

    // add default user data source
    if( !settings.contains( "userDataSources" ) ) {
        QStringList udsList;
        udsList << "http://files.kde.org/marble/satellites/PlanetarySatellites.msc";
        m_settings.insert( "userDataSources", udsList );
        userDataSourceAdded( udsList[0] );
    }
    else if( settings.value( "userDataSources" ).type() == QVariant::String ) {
        // same HACK as above
        m_settings.insert( "userDataSources",
            settings.value( "userDataSources" ).toString().split(QLatin1Char( ',' ) ) );
    }

    emit settingsChanged( nameId() );
}