⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newstuff.cpp.svn-base

📁 okular
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
            style += ".leftProgressContainer { width: 82px; height: 10px; background-color: transparent; }";            style += ".leftProgressBar { left: 1px; width: 0px; top: 1px; height: 8px; background-color: red; }";            style += ".contentsColumn { vertical-align: top; }";            style += ".contentsHeader { width: 100%; font-size: 120%; font-weight: bold; border-bottom: 1px solid #c8c8c8; }";            style += ".contentsBody {}";            style += ".contentsFooter {}";            style += ".star { width: 0px; height: 24px; background-image: url(" + starIconPath + "); background-repeat: repeat-x; }";            style += ".starbg { width: 110px; height: 24px; background-image: url(" + starBgIconPath + "); background-repeat: repeat-x; }";            setUserStyleSheet( style );        }        // handle clicks on page links/buttons        void urlSelected( const QString & link, int, int, const QString &, KParts::URLArgs )        {            KUrl url( link );            QString urlProtocol = url.protocol();            QString urlPath = url.path();            if ( urlProtocol == "mailto" )            {                // clicked over a mail address                KToolInvocation::invokeMailer( url );            }            else if ( urlProtocol == "item" )            {                // clicked over an item                bool ok;                unsigned long itemPointer = urlPath.toULong( &ok );                if ( !ok )                {                    kWarning() << "ItemsView: error converting item pointer." << endl;                    return;                }                // I love to cast pointers                AvailableItem * item = (AvailableItem *)itemPointer;                if ( !m_items.contains( item ) )                {                    kWarning() << "ItemsView: error retrieving item pointer." << endl;                    return;                }                // install/uninstall the item                if ( item->installed() )                    m_newStuffDialog->removeItem( item );   // synchronous                else                    m_newStuffDialog->installItem( item );  // asynchronous            }        }        // delete all the classes we own        void clear()        {            // delete all items and empty local list            AvailableItem::List::iterator it = m_items.begin(), iEnd = m_items.end();            for ( ; it != iEnd; ++it )                delete *it;            m_items.clear();        }    private:        NewStuffDialog * m_newStuffDialog;        AvailableItem::List m_items;        int m_sorting;};/** CORE/GUI: The main dialog that performs GHNS low level operations **//* internal storage structures to be used by NewStuffDialog */struct ProvidersListJobInfo // -> Provider(s){    KJob * job;    QString receivedData;};struct ProviderJobInfo      // -> AvailableItem(s){    QString receivedData;};struct ItemTransferInfo          // -> download files{    AvailableItem * item;};struct NewStuffDialogPrivate{    // Jobs (1 for fetching the list, unlimited for providers / items)    ProvidersListJobInfo providersListJob;    QMap< KJob *, ProviderJobInfo > providerJobs;    QMap< KJob *, ItemTransferInfo > transferJobs;    // Contents    QList< Provider * > providers;    // gui related vars    QWidget * parentWidget;    QLineEdit * searchLine;    QComboBox * typeCombo;    QComboBox * sortCombo;    ItemsView * itemsView;    QLabel * messageLabel;    // other classes    QTimer * messageTimer;    QTimer * networkTimer;};NewStuffDialog::NewStuffDialog( QWidget * parentWidget )    : QDialog( parentWidget ), d( new NewStuffDialogPrivate ){    setObjectName( "okularNewStuff" );    // initialize the private classes    d->providersListJob.job = 0;    d->parentWidget = parentWidget;    d->messageTimer = new QTimer( this );    d->messageTimer->setSingleShot( true );    connect( d->messageTimer, SIGNAL( timeout() ),             this, SLOT( slotResetMessageColors() ) );    d->networkTimer = new QTimer( this );    d->networkTimer->setSingleShot( true );    connect( d->networkTimer, SIGNAL( timeout() ),             this, SLOT( slotNetworkTimeout() ) );    // popuplate dialog with stuff    QBoxLayout * horLay = new QHBoxLayout( this );    horLay->setMargin( 11 );    // create left picture widget (if picture found)    QPixmap p( KStandardDirs::locate( "data", "okular/pics/ghns.png" ) );    if ( !p.isNull() )       horLay->addWidget( new ExtendImageWidget( p, this ) );    // create right 'main' widget    KVBox * rightLayouter = new KVBox( this );    rightLayouter->setSpacing( 6 );    horLay->addWidget( rightLayouter );      // create upper label      QLabel * mainLabel = new QLabel( i18n("All you ever wanted, in one click!"), rightLayouter);      QFont mainFont = mainLabel->font();      mainFont.setBold( true );      mainLabel->setFont( mainFont );      // create the control panel      QFrame * panelFrame = new QFrame( rightLayouter );      panelFrame->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );      QGridLayout * panelLayout = new QGridLayout( panelFrame );      panelLayout->setMargin( 11 );      panelLayout->setSpacing( 6 );        // add widgets to the control panel        QLabel * label1 = new QLabel( i18n("Show:"), panelFrame );        panelLayout->addWidget( label1, 0, 0 );        d->typeCombo = new QComboBox( panelFrame );        d->typeCombo->setEditable( false );        panelLayout->addWidget( d->typeCombo, 0, 1 );        d->typeCombo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );        d->typeCombo->setMinimumWidth( 150 );        d->typeCombo->setEnabled( false );        connect( d->typeCombo, SIGNAL( activated(int) ),                 this, SLOT( slotLoadProvider(int) ) );        QLabel * label2 = new QLabel( i18n("Order by:"), panelFrame );        panelLayout->addWidget( label2, 0, 2 );        d->sortCombo = new QComboBox( panelFrame );        d->sortCombo->setEditable( false );        panelLayout->addWidget( d->sortCombo, 0, 3 );        d->sortCombo->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );        d->sortCombo->setMinimumWidth( 100 );        d->sortCombo->setEnabled( false );        d->sortCombo->addItem( SmallIconSet( "fonts" ), i18n("Name") );        d->sortCombo->addItem( SmallIconSet( "knewstuff" ), i18n("Rating") );        d->sortCombo->addItem( SmallIconSet( "favorites" ), i18n("Downloads") );        connect( d->sortCombo, SIGNAL( activated(int) ),                 this, SLOT( slotSortingSelected(int) ) );        QLabel * label3 = new QLabel( i18n("Search:"), panelFrame );        panelLayout->addWidget( label3, 1, 0 );        d->searchLine = new QLineEdit( panelFrame );        panelLayout->addWidget( d->searchLine, 1, 1, 1, 3 );        d->searchLine->setEnabled( false );      // create the ItemsView used to display available items      d->itemsView = new ItemsView( this, rightLayouter );      // create bottom buttons      KHBox * bottomLine = new KHBox( rightLayouter );        // create info label        d->messageLabel = new QLabel( bottomLine );        d->messageLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );        d->messageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );        d->messageLabel->setAutoFillBackground( true );        // close button        KPushButton * closeButton = new KPushButton( bottomLine );        closeButton->setGuiItem( KStdGuiItem::close() );        //closeButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum )        connect( closeButton, SIGNAL( clicked() ), this, SLOT( accept() ) );    // start with a nice size    resize( 700, 400 );    slotResetMessageColors();    // start loading providers list    QTimer::singleShot( 100, this, SLOT( slotLoadProvidersList() ) );}NewStuffDialog::~NewStuffDialog(){    // cancel pending KJob(s) (don't like to leave orphaned threads alone)    if ( d->providersListJob.job )        d->providersListJob.job->kill();    QMap< KJob *, ProviderJobInfo >::iterator pIt = d->providerJobs.begin(), pEnd = d->providerJobs.end();    for ( ; pIt != pEnd; ++pIt )        pIt.key()->kill();    QMap< KJob *, ItemTransferInfo >::iterator tIt = d->transferJobs.begin(), tEnd = d->transferJobs.end();    for ( ; tIt != tEnd; ++tIt )        tIt.key()->kill();    // delete all Provider descriptors    QList< Provider * >::iterator it = d->providers.begin(), iEnd = d->providers.end();    for ( ; it != iEnd; ++it )        delete *it;    d->providers.clear();    // delete the private storage structure    delete d;}void NewStuffDialog::displayMessage( const QString & msg, MessageType type, int timeOutMs ){    // stop the pending timer if present    if ( d->messageTimer )        d->messageTimer->stop();    // set background color based on message type    switch ( type )    {        case Info:        {            QPalette pal = d->messageLabel->palette();            pal.setColor( QPalette::Window, pal.color( QPalette::Highlight ) );            pal.setColor( QPalette::WindowText, pal.color( QPalette::HighlightedText ) );            d->messageLabel->setPalette( pal );            break;        }        case Error:        {            QPalette pal = d->messageLabel->palette();            pal.setColor( QPalette::Window, Qt::red );            pal.setColor( QPalette::WindowText, Qt::white );            d->messageLabel->setPalette( pal );            break;        }        default:            slotResetMessageColors();            break;    }    // set text to messageLabel    d->messageLabel->setText( msg );    // single shot the resetColors timer (and create it if null)    d->messageTimer->start( timeOutMs );}void NewStuffDialog::installItem( AvailableItem * item ){    // safety check    if ( item->url().isEmpty() || item->destinationPath().isEmpty() )    {        displayMessage( i18n("I do not know how to install this. Sorry, my fault."), Info );        return;    }    //TODO check for AvailableItem deletion! (avoid broken pointers) -> cancel old jobs    slotDownloadItem( item );}void NewStuffDialog::removeItem( AvailableItem * item ){    // safety check    if ( item->destinationPath().isEmpty() )    {        displayMessage( i18n("I do not know how to uninstall this. Sorry, my fault."), Info );        return;    }    // delete file and update item state    KIO::NetAccess::del( item->destinationPath(), 0 );    item->setState( AvailableItem::Normal );    d->itemsView->updateItem( item );    // inform the user ...    displayMessage( i18n("%1 is no more installed.", item->name() ) );    // ... and any listening object    emit removedFile( item->name() );}void NewStuffDialog::slotResetMessageColors() // SLOT{    QPalette pal = d->messageLabel->palette();    QPalette qAppPal = QApplication::palette();    pal.setColor( QPalette::Window, qAppPal.color( QPalette::Window ) );    pal.setColor( QPalette::WindowText, qAppPal.color( QPalette::WindowText ) );    d->messageLabel->setPalette( pal );}void NewStuffDialog::slotNetworkTimeout() // SLOT{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -