示例#1
0
void ClockApplet::updateTipContent()
{
    Plasma::ToolTipContent tipData;

    QString subText("<table>");
    QList<Plasma::DataEngine::Data> tzs;
    Plasma::DataEngine *engine = dataEngine("time");
    Plasma::DataEngine::Data data = engine->query("Local");
    const QDate localDate = data["Date"].toDate();
    const QString localTz = data["Timezone"].toString();
    tzs.append(data);
    bool highlightLocal = false;

    const bool hasEvents = d->calendarWidget ? d->calendarWidget->dateHasDetails(localDate) : false;
    tipData.setMainText(hasEvents ? i18n("Current Time and Events") : i18n("Current Time"));

    foreach (const QString &tz, d->selectedTimezones) {
        if (tz != "UTC") {
            highlightLocal = true;
        }

        data = engine->query(tz);
        tzs.append(data);
    }

    qSort(tzs.begin(), tzs.end(), sortTzByData);
    QDate currentDate;
    foreach (const Plasma::DataEngine::Data &data, tzs) {
        bool shouldHighlight = highlightLocal && (data["Timezone"].toString() == localTz);
        currentDate = d->addTzToTipText(subText, data, currentDate, shouldHighlight);
    }
示例#2
0
void WebBrowser::urlChanged(const QUrl &url)
{
    //ask for a favicon
    Plasma::DataEngine *engine = dataEngine( "favicons" );
    if (engine) {
        //engine->disconnectSource( url.toString(), this );
        engine->connectSource( url.toString(), this );

        engine->query( url.toString() );
    }

    m_url = KUrl(url);

    if (m_bookmarkModel->match(m_bookmarkModel->index(0,0), BookmarkItem::UrlRole, m_url.prettyUrl()).isEmpty()) {
        m_addBookmark->setAction(m_addBookmarkAction);
    } else {
        m_addBookmark->setAction(m_removeBookmarkAction);
    }

    m_nativeHistoryCombo->addToHistory(m_url.prettyUrl());
    m_nativeHistoryCombo->setCurrentIndex(0);

    m_go->setAction(m_reloadAction);

    KConfigGroup cg = config();
    saveState(cg);

    m_back->setEnabled(m_browser->page()->history()->canGoBack());
    m_forward->setEnabled(m_browser->page()->history()->canGoForward());
    setAssociatedApplicationUrls(KUrl(url));
}
示例#3
0
void
TabsApplet::saveSettings()
{
    DEBUG_BLOCK
    KConfigGroup config = Amarok::config("Tabs Applet");

    bool fetchGuitar = ui_Settings.cbFetchGuitar->isChecked();
    bool fetchBass = ui_Settings.cbFetchBass->isChecked();

    // check if any setting has changed
    bool forceUpdate = false;
    if( m_fetchGuitar != fetchGuitar || m_fetchBass != fetchBass )
        forceUpdate = true;

    if( forceUpdate )
    {
        m_fetchGuitar = fetchGuitar;
        m_fetchBass = fetchBass;

        config.writeEntry( "FetchGuitar", m_fetchGuitar );
        config.writeEntry( "FetchBass", m_fetchBass );

        Plasma::DataEngine *engine = dataEngine( "amarok-tabs" );
        engine->setProperty( "fetchGuitarTabs", m_fetchGuitar );
        engine->setProperty( "fetchBassTabs", m_fetchBass );
        engine->query( QLatin1String( "tabs:forceUpdate" ) );
    }
}
示例#4
0
bool Hdd::addVisualization(const QString& source)
{
    Plasma::Meter *w;
    Plasma::DataEngine *engine = dataEngine("soliddevice");
    Plasma::DataEngine::Data data;

    if (!engine) {
        return false;
    }
    if (!isValidDevice(source, &data)) {
        // do not try to show hard drives and swap partitions.
        return false;
    }
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Horizontal);
    layout->setContentsMargins(3, 3, 3, 3);
    layout->setSpacing(5);

    w = new Plasma::Meter(this);
    w->setMeterType(Plasma::Meter::BarMeterHorizontal);
    if (mode() != SM::Applet::Panel) {
        MonitorIcon *icon = new MonitorIcon(this);
        m_icons.insert(source, icon);
        icon->setImage("drive-harddisk");
        if (data["Accessible"].toBool()) {
            QStringList overlays;
            overlays << QString("emblem-mounted");
            icon->setOverlays(overlays);
        }
        layout->addItem(icon);
    } else {
        w->setSvg("system-monitor/hdd_panel");
    }
    w->setLabel(0, hddTitle(source, data));
    w->setLabelAlignment(0, Qt::AlignVCenter | Qt::AlignLeft);
    w->setLabelAlignment(1, Qt::AlignVCenter | Qt::AlignRight);
    w->setLabelAlignment(2, Qt::AlignVCenter | Qt::AlignCenter);
    w->setMaximum(data["Size"].toULongLong() / (1024 * 1024));
    applyTheme(w);
    appendVisualization(source, w);
    layout->addItem(w);
    mainLayout()->addItem(layout);
    dataUpdated(source, data);
    setPreferredItemHeight(layout->preferredSize().height());

    QString disk = data["Parent UDI"].toString();

    m_diskMap[disk] << w;
    if (!connectedSources().contains(disk)) {
        data = engine->query(disk);
        dataUpdated(disk, data);
        connectSource(disk);
    }
    return true;
}
示例#5
0
void
PhotosApplet::saveSettings()
{
    DEBUG_BLOCK
    KConfigGroup config = Amarok::config("Photos Applet");

    m_nbPhotos = ui_Settings.photosSpinBox->value();
    m_Animation = ui_Settings.animationComboBox->currentText();
    m_KeyWords = ui_Settings.additionalkeywordsLineEdit->text().split(", ");
    config.writeEntry( "NbPhotos", m_nbPhotos );
    config.writeEntry( "Animation", m_Animation );
    config.writeEntry( "KeyWords", m_KeyWords );

    m_widget->setMode( ui_Settings.animationComboBox->currentIndex() );
    m_widget->clear();

    Plasma::DataEngine *engine = dataEngine( "amarok-photos" );
    engine->setProperty( "fetchSize", m_nbPhotos );
    engine->setProperty( "keywords", m_KeyWords );
    engine->query( QLatin1String( "photos:forceUpdate" ) );
}
示例#6
0
void
TabsApplet::reloadTabs()
{
    DEBUG_BLOCK
    KDialog reloadDialog;
    QWidget *reloadWidget = new QWidget( &reloadDialog );

    Ui::ReloadEditDialog *reloadUI = new Ui::ReloadEditDialog();
    reloadUI->setupUi( reloadWidget );

    reloadDialog.setCaption( i18nc( "Guitar tablature", "Reload Tabs" ) );
    reloadDialog.setButtons( KDialog::Ok|KDialog::Cancel );
    reloadDialog.setDefaultButton( KDialog::Ok );
    reloadDialog.setMainWidget( reloadWidget );

    // query engine for current artist and title
    Plasma::DataEngine *engine = dataEngine( "amarok-tabs" );
    QString artistName = engine->property( "artistName" ).toString();
    QString titleName = engine->property( "titleName" ).toString();

    // update ui
    reloadUI->artistLineEdit->setText( artistName );
    reloadUI->titleLineEdit->setText( titleName );

    if( reloadDialog.exec() == KDialog::Accepted )
    {
        QString newArtist = reloadUI->artistLineEdit->text();
        QString newTitle = reloadUI->titleLineEdit->text();
        if ( newArtist != artistName || newTitle != titleName )
        {
            engine->setProperty( "artistName", newArtist );
            engine->setProperty( "titleName", newTitle );
            engine->query( QLatin1String( "tabs:forceUpdateSpecificTitleArtist" ) );
        }
    }
}
示例#7
0
void
SimilarArtistsApplet::init()
{
    DEBUG_BLOCK

    // Call the base implementation.
    Context::Applet::init();

    enableHeader( true );
    setHeaderText( i18n( "Similar Artists" ) );

    QAction* backwardAction = new QAction( this );
    backwardAction->setIcon( KIcon( "go-previous" ) );
    backwardAction->setEnabled( false );
    backwardAction->setText( i18n( "Back" ) );
    m_backwardIcon = addLeftHeaderAction( backwardAction );
    connect( m_backwardIcon, SIGNAL(clicked()), this, SLOT(goBackward()) );

    QAction* forwardAction = new QAction( this );
    forwardAction->setIcon( KIcon( "go-next" ) );
    forwardAction->setEnabled( false );
    forwardAction->setText( i18n( "Forward" ) );
    m_forwardIcon = addLeftHeaderAction( forwardAction );
    connect( m_forwardIcon, SIGNAL(clicked()), this, SLOT(goForward()) );

    QAction *currentAction = new QAction( this );
    currentAction->setIcon( KIcon( "filename-artist-amarok" ) );
    currentAction->setEnabled( true );
    currentAction->setText( i18n( "Show Similar Artists for Currently Playing Track" ) );
    m_currentArtistIcon = addRightHeaderAction( currentAction );
    connect( m_currentArtistIcon, SIGNAL(clicked()), this, SLOT(queryForCurrentTrack()) );

    QAction* settingsAction = new QAction( this );
    settingsAction->setIcon( KIcon( "preferences-system" ) );
    settingsAction->setEnabled( true );
    settingsAction->setText( i18n( "Settings" ) );
    m_settingsIcon = addRightHeaderAction( settingsAction );
    connect( m_settingsIcon, SIGNAL(clicked()), this, SLOT(configure()) );

    setCollapseOffHeight( -1 );
    setCollapseHeight( m_header->height() );
    setMinimumHeight( collapseHeight() );
    setPreferredHeight( collapseHeight() );

    // create a scrollarea
    m_scroll = new ArtistsListWidget( this );
    m_scroll->hide();
    connect( m_scroll, SIGNAL(showSimilarArtists(QString)), SLOT(showSimilarArtists(QString)) );
    connect( m_scroll, SIGNAL(showBio(QString)), SLOT(showArtistBio(QString)) );

    m_layout = new QGraphicsLinearLayout( Qt::Vertical, this );
    m_layout->addItem( m_header );
    m_layout->addItem( m_scroll );
    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

    // Read config and inform the engine.
    KConfigGroup config = Amarok::config( "SimilarArtists Applet" );
    m_maxArtists = config.readEntry( "maxArtists", "5" ).toInt();

    Plasma::DataEngine *engine = dataEngine( "amarok-similarArtists" );
    connect( engine, SIGNAL(sourceAdded(QString)), SLOT(connectSource(QString)) );
    engine->setProperty( "maximumArtists", m_maxArtists );
    engine->query( "similarArtists" );
}
示例#8
0
void SwitchWindow::makeMenu()
{
    m_menu->clear();
    Plasma::DataEngine *tasks = dataEngine("tasks");
    if (!tasks->isValid()) {
        return;
    }

    QMultiHash<int, QAction*> desktops;

    //make all the window actions
    foreach (const QString &source, tasks->sources()) {
        Plasma::DataEngine::Data window = tasks->query(source);
        if (window.value("startup").toBool()) {
            //kDebug() << "skipped fake task" << source;
            continue;
        }
        if (!window.value("onCurrentActivity").toBool()) {
            continue;
        }

        QString name = window.value("visibleNameWithState").toString();
        if (name.isEmpty()) {
            kDebug() << "failed source" << source;
            continue;
        }

        QAction *action = new QAction(name, m_menu);
        action->setIcon(window.value("icon").value<QIcon>());
        action->setData(source);
        desktops.insert(window.value("desktop").toInt(), action);
    }

    //sort into menu
    if (m_mode == CurrentDesktop) {
        int currentDesktop = KWindowSystem::currentDesktop();
        m_menu->addTitle(i18n("Windows"));
        m_menu->addActions(desktops.values(currentDesktop));
        m_menu->addActions(desktops.values(-1));
    } else {
        int numDesktops = KWindowSystem::numberOfDesktops();
        if (m_mode == AllFlat) {
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                    QString name = KWindowSystem::desktopName(i);
                    name = QString("%1: %2").arg(i).arg(name);
                    m_menu->addTitle(name);
                    m_menu->addActions(desktops.values(i));
                }
            }
            if (desktops.contains(-1)) {
                m_menu->addTitle(i18n("All Desktops"));
                m_menu->addActions(desktops.values(-1));
            }
        } else { //submenus
            for (int i = 1; i <= numDesktops; ++i) {
                if (desktops.contains(i)) {
                        QString name = KWindowSystem::desktopName(i);
                        name = QString("%1: %2").arg(i).arg(name);
                        KMenu *subMenu = new KMenu(name, m_menu);
                        subMenu->addActions(desktops.values(i));
                        m_menu->addMenu(subMenu);
                }
            }
            if (desktops.contains(-1)) {
                KMenu *subMenu = new KMenu(i18n("All Desktops"), m_menu);
                subMenu->addActions(desktops.values(-1));
                m_menu->addMenu(subMenu);
            }
        }
    }

    m_menu->adjustSize();
}