fileInstallWidget.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 static const char *fileinstallwidget_id =
00032 "$Id: fileInstallWidget.cc,v 1.35 2003/10/13 14:55:02 kainhofe Exp $";
00033
00034 #ifndef _KPILOT_OPTIONS_H
00035 #include "options.h"
00036 #endif
00037
00038 #include <unistd.h>
00039
00040 #include <qlistbox.h>
00041 #include <qstring.h>
00042 #include <qlabel.h>
00043 #include <qpushbutton.h>
00044 #include <qlayout.h>
00045 #include <qwhatsthis.h>
00046 #include <qmultilineedit.h>
00047
00048 #include <kfiledialog.h>
00049 #include <kurldrag.h>
00050
00051 #include "kpilotConfig.h"
00052 #include "fileInstaller.h"
00053
00054
00055 #include "fileInstallWidget.moc"
00056
00057 FileInstallWidget::FileInstallWidget(QWidget * parent,
00058 const QString & path) :
00059 PilotComponent(parent, "component_files", path),
00060 fSaveFileList(false),
00061 fInstaller(0L)
00062 {
00063 FUNCTIONSETUP;
00064
00065 QGridLayout *grid = new QGridLayout(this, 5, 5, SPACING);
00066
00067 QLabel *label = new QLabel(i18n("Files to install:"), this);
00068
00069 grid->addWidget(label, 1, 1);
00070
00071 QPushButton *abutton;
00072
00073 abutton = clearButton= new QPushButton(i18n("Clear List"), this);
00074
00075 connect(abutton, SIGNAL(clicked()), this, SLOT(slotClearButton()));
00076 grid->addWidget(abutton, 3, 1);
00077 QWhatsThis::add(abutton,
00078 i18n
00079 ("<qt>Clear the list of files to install. No files will be installed.</qt>"));
00080
00081 abutton = addButton = new QPushButton(i18n("Add File..."), this);
00082 connect(abutton, SIGNAL(clicked()), this, SLOT(slotAddFile()));
00083 grid->addWidget(abutton, 4, 1);
00084 QWhatsThis::add(abutton,
00085 i18n
00086 ("<qt>Choose a file to add to the list of files to install.</qt>"));
00087
00088 fListBox = new QListBox(this);
00089 grid->addMultiCellWidget(fListBox, 1, 4, 2, 3);
00090 QWhatsThis::add(fListBox,
00091 i18n
00092 ("<qt>This lists files that will be installed on the Pilot during the next HotSync. Drag files here or use the Add button.</qt>"));
00093
00094 grid->setRowStretch(2, 100);
00095 grid->setColStretch(2, 50);
00096 grid->setColStretch(2, 50);
00097 grid->addColSpacing(4, SPACING);
00098 grid->addRowSpacing(5, SPACING);
00099
00100 fInstaller = new FileInstaller;
00101 connect(fInstaller, SIGNAL(filesChanged()),
00102 this, SLOT(refreshFileInstallList()));
00103
00104 setAcceptDrops(true);
00105
00106 (void) fileinstallwidget_id;
00107 }
00108
00109 FileInstallWidget::~FileInstallWidget()
00110 {
00111 KPILOT_DELETE(fInstaller);
00112 }
00113
00114 void FileInstallWidget::dragEnterEvent(QDragEnterEvent * event)
00115 {
00116 FUNCTIONSETUP;
00117 event->accept(KURLDrag::canDecode(event));
00118 }
00119
00120
00121 void FileInstallWidget::dropEvent(QDropEvent * drop)
00122 {
00123 FUNCTIONSETUP;
00124 if (!shown) return;
00125
00126 KURL::List list;
00127
00128 if (!KURLDrag::decode(drop, list) || list.isEmpty())
00129 return;
00130
00131 #ifdef DEBUG
00132 DEBUGKPILOT << ": Got " << list.first().prettyURL() << endl;
00133 #endif
00134
00135 QStringList files;
00136 for(KURL::List::ConstIterator it = list.begin(); it != list.end(); ++it)
00137 {
00138 if ((*it).isLocalFile())
00139 files << (*it).path();
00140 }
00141
00142 fInstaller->addFiles(files, this );
00143 }
00144
00145 void FileInstallWidget::slotClearButton()
00146 {
00147 FUNCTIONSETUP;
00148 fInstaller->clearPending();
00149 }
00150
00151 void FileInstallWidget::showComponent()
00152 {
00153 FUNCTIONSETUP;
00154 refreshFileInstallList();
00155 }
00156
00157 void FileInstallWidget::slotAddFile()
00158 {
00159 FUNCTIONSETUP;
00160 if (!shown) return;
00161
00162 QStringList fileNames = KFileDialog::getOpenFileNames();
00163
00164 for (QStringList::Iterator fileName = fileNames.begin(); fileName != fileNames.end(); ++fileName)
00165 {
00166 fInstaller->addFile(*fileName, this );
00167 }
00168 }
00169
00170 bool FileInstallWidget::preHotSync(QString &)
00171 {
00172 FUNCTIONSETUP;
00173
00174 fListBox->setEnabled(false);
00175 fInstaller->setEnabled(false);
00176 addButton->setEnabled(false);
00177 clearButton->setEnabled(false);
00178
00179 return true;
00180 }
00181
00182 void FileInstallWidget::postHotSync()
00183 {
00184 FUNCTIONSETUP;
00185 fInstaller->setEnabled(true);
00186 fListBox->setEnabled(true);
00187 addButton->setEnabled(true);
00188 clearButton->setEnabled(true);
00189 if (shown) refreshFileInstallList();
00190 }
00191
00192
00193 void FileInstallWidget::refreshFileInstallList()
00194 {
00195 FUNCTIONSETUP;
00196
00197 fListBox->clear();
00198 fListBox->insertStringList(fInstaller->fileNames());
00199 }
00200
00201
This file is part of the documentation for kpilot Library Version 3.2.2.