"Fossies" - the Fresh Open Source Software Archive

Member "digikam-6.3.0/core/libs/album/widgets/albumselectdialog.cpp" (4 Sep 2019, 4939 Bytes) of package /linux/misc/digikam-6.3.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "albumselectdialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.2.0_vs_6.3.0.

    1 /* ============================================================
    2  *
    3  * This file is a part of digiKam project
    4  * https://www.digikam.org
    5  *
    6  * Date        : 2005-06-16
    7  * Description : a dialog to select a target album to download
    8  *               pictures from camera
    9  *
   10  * Copyright (C) 2005      by Renchi Raju <renchi dot raju at gmail dot com>
   11  * Copyright (C) 2006-2019 by Gilles Caulier <caulier dot gilles at gmail dot com>
   12  *
   13  * This program is free software; you can redistribute it
   14  * and/or modify it under the terms of the GNU General
   15  * Public License as published by the Free Software Foundation;
   16  * either version 2, or (at your option)
   17  * any later version.
   18  *
   19  * This program is distributed in the hope that it will be useful,
   20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22  * GNU General Public License for more details.
   23  *
   24  * ============================================================ */
   25 
   26 #include "albumselectdialog.h"
   27 
   28 // Qt includes
   29 
   30 #include <QLabel>
   31 #include <QGridLayout>
   32 #include <QPixmap>
   33 #include <QPointer>
   34 #include <QStandardPaths>
   35 #include <QApplication>
   36 #include <QStyle>
   37 #include <QDialogButtonBox>
   38 #include <QVBoxLayout>
   39 #include <QPushButton>
   40 
   41 // KDE includes
   42 
   43 #include <klocalizedstring.h>
   44 
   45 // Local includes
   46 
   47 #include "album.h"
   48 #include "albummanager.h"
   49 #include "albumselectwidget.h"
   50 #include "albumthumbnailloader.h"
   51 #include "collectionmanager.h"
   52 #include "dxmlguiwindow.h"
   53 
   54 namespace Digikam
   55 {
   56 
   57 class Q_DECL_HIDDEN AlbumSelectDialog::Private
   58 {
   59 
   60 public:
   61 
   62     explicit Private()
   63     {
   64         buttons   = nullptr;
   65         albumSel  = nullptr;
   66         searchBar = nullptr;
   67     }
   68 
   69     QDialogButtonBox*  buttons;
   70 
   71     AlbumSelectWidget* albumSel;
   72 
   73     SearchTextBar*     searchBar;
   74 };
   75 
   76 AlbumSelectDialog::AlbumSelectDialog(QWidget* const parent, PAlbum* const albumToSelect, const QString& header)
   77     : QDialog(parent),
   78       d(new Private)
   79 {
   80     setWindowTitle(i18n("Select Album"));
   81 
   82     d->buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
   83     d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
   84 
   85     // -------------------------------------------------------------
   86 
   87     QWidget* const page     = new QWidget(this);
   88     QGridLayout* const grid = new QGridLayout(page);
   89     QLabel* const logo      = new QLabel(page);
   90     logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48)));
   91 
   92     QLabel* const message   = new QLabel(page);
   93     message->setWordWrap(true);
   94 
   95     if (!header.isEmpty())
   96     {
   97         message->setText(header);
   98     }
   99 
  100     d->albumSel = new AlbumSelectWidget(page, albumToSelect, true);
  101 
  102     grid->addWidget(logo,        0, 0, 1, 1);
  103     grid->addWidget(message,     1, 0, 1, 1);
  104     grid->addWidget(d->albumSel, 0, 1, 3, 1);
  105     grid->setColumnStretch(1, 10);
  106     grid->setRowStretch(2, 10);
  107     grid->setContentsMargins(QMargins());
  108     grid->setSpacing(QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
  109 
  110     QVBoxLayout* const vbx = new QVBoxLayout(this);
  111     vbx->addWidget(page);
  112     vbx->addWidget(d->buttons);
  113     setLayout(vbx);
  114 
  115     // -------------------------------------------------------------
  116 
  117     connect(d->albumSel, SIGNAL(itemSelectionChanged()),
  118             this, SLOT(slotSelectionChanged()));
  119 
  120     connect(d->albumSel, SIGNAL(completerActivated()),
  121             this, SLOT(accept()));
  122 
  123     connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
  124             this, SLOT(accept()));
  125 
  126     connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()),
  127             this, SLOT(reject()));
  128 
  129     connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()),
  130             this, SLOT(slotHelp()));
  131 
  132     // -------------------------------------------------------------
  133 
  134     resize(500, 500);
  135     slotSelectionChanged();
  136 }
  137 
  138 AlbumSelectDialog::~AlbumSelectDialog()
  139 {
  140     delete d;
  141 }
  142 
  143 void AlbumSelectDialog::slotSelectionChanged()
  144 {
  145     PAlbum* const currentAlbum = d->albumSel->currentAlbum();
  146 
  147     if (!currentAlbum || (currentAlbum->isRoot()))
  148     {
  149         d->buttons->button(QDialogButtonBox::Ok)->setEnabled(false);
  150         return;
  151     }
  152 
  153     d->buttons->button(QDialogButtonBox::Ok)->setEnabled(true);
  154 }
  155 
  156 PAlbum* AlbumSelectDialog::selectAlbum(QWidget* const parent, PAlbum* const albumToSelect, const QString& header)
  157 {
  158     QPointer<AlbumSelectDialog> dlg = new AlbumSelectDialog(parent, albumToSelect, header);
  159 
  160     if (dlg->exec() != QDialog::Accepted)
  161     {
  162         delete dlg;
  163         return nullptr;
  164     }
  165 
  166     PAlbum* const selectedAlbum = dlg->d->albumSel->currentAlbum();
  167 
  168     if (!selectedAlbum || (selectedAlbum->isRoot()))
  169     {
  170         delete dlg;
  171         return nullptr;
  172     }
  173 
  174     delete dlg;
  175 
  176     return selectedAlbum;
  177 }
  178 
  179 void AlbumSelectDialog::slotHelp()
  180 {
  181     DXmlGuiWindow::openHandbook();
  182 }
  183 
  184 } // namespace Digikam