📄 cleanupwizard.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#ifdef QTOPIA_PHONE#include "cleanupwizard.h"#else#include "cleanupwizard_pda.h"#endif#include <qtopia/applnk.h>#include <qtopia/global.h>#include <qtopia/contextbar.h>#include <qtopia/qpeapplication.h>#include <qtopia/services.h>#include <qtopia/datetimeedit.h>#ifdef Q_WS_QWS#include <qtopia/qcopenvelope_qws.h>#endif#include <qdialog.h>#include <qlayout.h>#include <qlabel.h>#include <qcheckbox.h>#include <qspinbox.h>#include <qlistview.h>#include <qfileinfo.h>#include <qlist.h>#include <qpushbutton.h>#include <qheader.h>#include <qgroupbox.h>#include <qtimer.h>#include <qmessagebox.h>#include <qprogressbar.h>#include <qgrid.h>class FinalCleanupWidget : public QWidget{ Q_OBJECT public: FinalCleanupWidget(QWidget *p = 0, const char* name = 0, WFlags f = 0) :QWidget(p, name, f) { QVBoxLayout* vl = new QVBoxLayout(this); vl->setSpacing( 6 ); vl->setMargin( 0 ); summary = new QLabel(this, "summaryLabel"); summary->setAlignment(Qt::AlignLeft | Qt::AlignTop); summary->setTextFormat(Qt::RichText); vl->addWidget(summary); text = ""; }; void setResult(const QString& newResult) { text = newResult; }; void appendResult(const QString& result) { if (text.isEmpty()) text = "<ul>"; // no tr text = text.append(result); }; void reset() { text = ""; }; protected: void showEvent(QShowEvent* se) { if (text.isEmpty()) text = tr("No actions have been taken to cleanup the device."); else { text = text.append("</ul>"); //no tr text = text.prepend(tr("The following items have been deleted:")); } summary->setText(text); setFocus(); QWidget::showEvent(se); }; private: QString text; QLabel *summary;};class PreselectionWidget : public QWidget{ Q_OBJECT public: PreselectionWidget(QWidget *p = 0, const char* name = 0, WFlags f =0) :QWidget(p, name, f) { QVBoxLayout* vl = new QVBoxLayout(this); vl->setSpacing( 6 ); vl->setMargin( 0 ); #ifdef QTOPIA_PHONE vl->addWidget(new QLabel("<qt>" + tr("What would you like to clean up?") + "</qt>", this));#endif doc = new QCheckBox(tr("Documents"), this, "doc_checkbox"); vl->addWidget( doc ); mail = new QCheckBox(tr("Messages"), this, "mail_checkbox"); vl->addWidget( mail ); datebook = new QCheckBox(tr("Events"), this, "datebook_checkbox"); vl->addWidget( datebook ); init(); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); vl->addItem(spacer); }; void init() { doc->setChecked( FALSE ); mail->setChecked( FALSE ); datebook->setChecked( FALSE ); }; private: QCheckBox *doc, *mail, *datebook; friend class CleanupWizard;};class DocSummaryWidget : public QWidget { Q_OBJECT public: DocSummaryWidget(QWidget* p = 0, const char* name = 0, WFlags f = 0) :QWidget(p, name, f) { QVBoxLayout* l = new QVBoxLayout(this); l->setSpacing( 6 ); l->setMargin( 0 ); progress = new QProgressBar(this, "Progressbar" ); progress->setFrameStyle( QFrame::Panel | QFrame::Sunken ); progress->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); progress->setIndicatorFollowsStyle( TRUE ); progress->setCenterIndicator( TRUE ); l->addWidget(progress); desc = new QLabel("", this); //no tr desc->setAlignment(Qt::AlignHCenter); l->addWidget(desc); pb = new QPushButton(this); l->addWidget(pb); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); l->addItem(spacer); }; virtual ~DocSummaryWidget() {}; void monitorFileDeletion(int fileSize) { if (fileSize) { pb->setText(tr("Cancel")); pb->show(); desc->setText(tr("Starting Cleanup")); progress->reset(); progress->setTotalSteps(fileSize); progress->show(); } else { pb->hide(); progress->hide(); desc->setText(tr("<qt>No action was selected.</qt>")); desc->setFocus(); //update ContextBar } }; public slots: void docDeleted(const QString& fileName, int fileSize) { static int docCount = 0; if (!deleted) docCount = 0; if (fileSize > 0) { docCount++; deleted+=fileSize; progress->setProgress( deleted ); desc->setText(tr("Deleting... ") + fileName); } else { desc->setText(fileName); pb->hide(); desc->setFocus(); //update ContextBar if (deleted) emit docCleanupFinished(docCount); } }; signals: void startDocCleanup(); void docCleanupFinished(int docCount); protected: void showEvent(QShowEvent *se) { QTimer::singleShot(1000, this, SIGNAL(startDocCleanup())); deleted=0; pb->show(); QWidget::showEvent(se); }; private: QLabel * desc; QPushButton * pb; QProgressBar * progress; int deleted; friend class CleanupWizard;};class DocCleanWidget: public QWidget{ Q_OBJECT public: DocCleanWidget(QWidget* p = 0, const char* name = 0, WFlags f = 0) :QWidget(p, name, f) { QVBoxLayout* vl = new QVBoxLayout(this); vl->setSpacing( 6 ); vl->setMargin( 0 );#ifdef QTOPIA_PHONE vl->addWidget(new QLabel(tr("<qt>Cleanup Documents</qt>"), this)); QFrame *line = new QFrame( this, "Line"); line->setFrameStyle(QFrame::HLine | QFrame::Sunken ); vl->addWidget(line);#endif QGrid* grid = new QGrid(2, this ) ; new QLabel(tr("bigger than"), grid); sizeBox = new QSpinBox(grid); sizeBox->setButtonSymbols(QSpinBox::UpDownArrows); sizeBox->setSuffix(" " + tr("kB", "KiloByte")); sizeBox->setMinValue( 0 ); sizeBox->setMaxValue( 100000 ); sizeBox->setValue( 10 ); sizeBox->setLineStep( 10 ); vl->addWidget(grid); QGroupBox* mediatypes = new QGroupBox(tr("Document types"), this); mediatypes->setColumnLayout( 0, Qt::Vertical ); mediatypes->layout()->setSpacing( 1 ); QGridLayout *mediaLayout = new QGridLayout(mediatypes->layout(), 2, 2, 1); audio = new QCheckBox(tr("Audio"), mediatypes); mediaLayout->addWidget(audio, 0, 0); audio->setChecked(FALSE); pictures = new QCheckBox(tr("Pictures"), mediatypes); mediaLayout->addWidget(pictures, 1, 0); pictures->setChecked(FALSE); text = new QCheckBox(tr("Text"), mediatypes); mediaLayout->addWidget(text, 1, 1); text->setChecked(FALSE); video = new QCheckBox(tr("Video"), mediatypes); mediaLayout->addWidget(video, 0, 1); video->setChecked(FALSE); vl->addWidget(mediatypes); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); vl->addItem(spacer); }; virtual ~DocCleanWidget() {}; private: QSpinBox *sizeBox; QCheckBox* audio, *video, *text, *pictures; friend class CleanupWizard;};class DocCheckListItem: public QObject, public QCheckListItem { Q_OBJECT public: DocCheckListItem(QListView* list, const QString& text, Type tt, DocLnk& dl) : QObject(list), QCheckListItem(list, text, tt) { dlk = dl; setPixmap(0, dl.pixmap()); }; DocLnk& docLink() { return dlk; }; protected: void stateChange(bool b) { int size = QFileInfo(dlk.file()).size(); if (b) emit selectionChanged(size); else emit selectionChanged(-size); }; signals: void selectionChanged(int size); private: DocLnk dlk;};class DocResultWidget: public QWidget{ Q_OBJECT public: DocResultWidget(QWidget*p = 0, const char* name = 0, WFlags f = 0) :QWidget(p, name, f),#ifdef QTOPIA_PHONE tooltip(0), timer(0), #endif cleanupStopped( FALSE ) { QVBoxLayout * vl = new QVBoxLayout(this); vl->setSpacing( 6 ); vl->setMargin( 0 ); summary = new QLabel("", this); //no tr vl->addWidget(summary); details = new QPushButton(this); vl->addWidget(details); list = new QListView(this, "DocumentListView"); list->addColumn(tr("Document")); list->addColumn(tr("Size")); list->header()->hide(); list->setMinimumHeight(60);#ifdef QTOPIA_PHONE connect(list , SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(documentSelected(QListViewItem *)));#endif vl->addWidget(list); QSpacerItem *spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); vl->addItem(spacer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -