Warning, file /sdk/cervisia/addremovedialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (C) 1999-2002 Bernd Gehrmann
0003  *                          bernd@mail.berlios.de
0004  *  Copyright (c) 2003-2007 Christian Loose <christian.loose@hamburg.de>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0019  */
0020 
0021 #include "addremovedialog.h"
0022 
0023 // Qt
0024 #include <QDialogButtonBox>
0025 #include <QFileInfo>
0026 #include <QLabel>
0027 #include <QListWidget>
0028 #include <QPushButton>
0029 #include <QStringList>
0030 #include <QVBoxLayout>
0031 
0032 // KDE
0033 #include <KHelpClient>
0034 #include <KLocalizedString>
0035 #include <KMessageWidget>
0036 
0037 AddRemoveDialog::AddRemoveDialog(ActionType action, QWidget *parent)
0038     : QDialog(parent)
0039 {
0040     setWindowTitle((action == Add) ? i18n("CVS Add") : (action == AddBinary) ? i18n("CVS Add Binary") : i18n("CVS Remove"));
0041     setModal(true);
0042 
0043     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
0044 
0045     auto mainLayout = new QVBoxLayout;
0046     setLayout(mainLayout);
0047 
0048     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0049     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0050 
0051     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0052     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0053     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &AddRemoveDialog::slotHelp);
0054 
0055     // Also give the focus to the OK button, otherwise the Help button gets focus
0056     // and is activated by Key_Return
0057     okButton->setFocus();
0058 
0059     auto textlabel = new QLabel((action == Add)             ? i18n("Add the following files to the repository:")
0060                                     : (action == AddBinary) ? i18n("Add the following binary files to the repository:")
0061                                                             : i18n("Remove the following files from the repository:"));
0062 
0063     mainLayout->addWidget(textlabel);
0064 
0065     m_listBox = new QListWidget;
0066     m_listBox->setSelectionMode(QAbstractItemView::NoSelection);
0067 
0068     mainLayout->addWidget(m_listBox);
0069 
0070     // Add warning message to dialog when user wants to remove a file
0071     if (action == Remove) {
0072         auto warning =
0073             new KMessageWidget(i18n("This will also remove the files from "
0074                                     "your local working copy."));
0075 
0076         warning->setIcon(QIcon::fromTheme("dialog-warning").pixmap(32));
0077         warning->setCloseButtonVisible(false);
0078 
0079         mainLayout->addSpacing(5);
0080         mainLayout->addWidget(warning);
0081         mainLayout->addSpacing(5);
0082     }
0083 
0084     if (action == Remove)
0085         helpTopic = "removingfiles";
0086     else
0087         helpTopic = "addingfiles";
0088 
0089     mainLayout->addWidget(buttonBox);
0090     okButton->setDefault(true);
0091 }
0092 
0093 void AddRemoveDialog::slotHelp()
0094 {
0095     KHelpClient::invokeHelp(helpTopic);
0096 }
0097 
0098 void AddRemoveDialog::setFileList(const QStringList &files)
0099 {
0100     // the dot for the root directory is hard to see, so
0101     // we convert it to the absolut path
0102     if (files.contains(".")) {
0103         QStringList copy(files);
0104         int idx = copy.indexOf(".");
0105         copy[idx] = QFileInfo(".").absoluteFilePath();
0106 
0107         m_listBox->addItems(copy);
0108     } else
0109         m_listBox->addItems(files);
0110 }
0111 
0112 // kate: space-indent on; indent-width 4; replace-tabs on;