1 /* This file is part of the KDE project
2  * Copyright (C) 2008 Fredy Yanardi <fyanardi@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "KPrConfigureSlideShowDialog.h"
21 
22 #include <QDesktopWidget>
23 
24 #include <klocalizedstring.h>
25 
26 #include "StageDebug.h"
27 #include "KPrDocument.h"
28 #include "KPrView.h"
29 #include "KPrCustomSlideShows.h"
30 #include "KPrViewModeSlidesSorter.h"
31 
KPrConfigureSlideShowDialog(KPrDocument * document,KPrView * parent)32 KPrConfigureSlideShowDialog::KPrConfigureSlideShowDialog( KPrDocument *document, KPrView *parent )
33     : KoDialog( parent )
34     , m_document( document )
35     , m_view(parent)
36 {
37     QWidget *widget = new QWidget( this );
38 
39     ui.setupUi( widget );
40 
41     ui.slidesComboBox->addItem( i18n( "All slides" ) );
42     KPrCustomSlideShows *customSlideShows = document->customSlideShows();
43     ui.slidesComboBox->addItems( customSlideShows->names() );
44 
45     setMainWidget( widget );
46 
47     setCaption( i18n( "Configure Slide Show" ) );
48 
49     QString activeCustomSlideShow = document->activeCustomSlideShow();
50     if ( activeCustomSlideShow.isEmpty() ) {
51         ui.slidesComboBox->setCurrentIndex( 0 );
52     }
53     else {
54         QList<QString> customSlideShows = document->customSlideShows()->names();
55         int index = customSlideShows.indexOf( activeCustomSlideShow ) + 1;
56         Q_ASSERT( index < ui.slidesComboBox->count() );
57         ui.slidesComboBox->setCurrentIndex( index );
58     }
59 
60     connect( ui.editSlidesButton, SIGNAL(clicked()), this, SLOT(editCustomSlideShow()) );
61 }
62 
activeCustomSlideShow() const63 QString KPrConfigureSlideShowDialog::activeCustomSlideShow() const
64 {
65     if ( ui.slidesComboBox->currentIndex() != 0 ) {
66         return ui.slidesComboBox->currentText();
67     }
68 
69     return QString();
70 }
71 
editCustomSlideShow()72 void KPrConfigureSlideShowDialog::editCustomSlideShow()
73 {
74     m_view->slidesSorter()->setActiveCustomSlideShow(ui.slidesComboBox->currentIndex());
75     m_view->showSlidesSorter();
76     accept();
77 }
78