KIO
kbuildsycocaprogressdialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003 Waldo Bastian <bastian@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #include "kbuildsycocaprogressdialog.h" 00019 #include <ksycoca.h> 00020 #include <kprocess.h> 00021 #include <kstandarddirs.h> 00022 #include <klocale.h> 00023 #include <QtDBus/QtDBus> 00024 00025 class KBuildSycocaProgressDialogPrivate 00026 { 00027 public: 00028 KBuildSycocaProgressDialogPrivate( KBuildSycocaProgressDialog *parent ) 00029 : m_parent(parent) 00030 { 00031 } 00032 00033 void _k_slotProgress(); 00034 void _k_slotFinished(); 00035 00036 KBuildSycocaProgressDialog *m_parent; 00037 QTimer m_timer; 00038 int m_timeStep; 00039 }; 00040 00041 void KBuildSycocaProgressDialog::rebuildKSycoca(QWidget *parent) 00042 { 00043 KBuildSycocaProgressDialog dlg(parent, 00044 i18n("Updating System Configuration"), 00045 i18n("Updating system configuration.")); 00046 00047 QDBusInterface kbuildsycoca("org.kde.kded", "/kbuildsycoca", 00048 "org.kde.kbuildsycoca"); 00049 if (kbuildsycoca.isValid()) { 00050 kbuildsycoca.callWithCallback("recreate", QVariantList(), &dlg, SLOT(_k_slotFinished())); 00051 } else { 00052 // kded not running, e.g. when using keditfiletype out of a KDE session 00053 QObject::connect(KSycoca::self(), SIGNAL(databaseChanged(QStringList)), &dlg, SLOT(_k_slotFinished())); 00054 KProcess* proc = new KProcess(&dlg); 00055 (*proc) << KStandardDirs::findExe(KBUILDSYCOCA_EXENAME); 00056 proc->start(); 00057 } 00058 dlg.exec(); 00059 } 00060 00061 KBuildSycocaProgressDialog::KBuildSycocaProgressDialog(QWidget *_parent, 00062 const QString &_caption, const QString &text) 00063 : QProgressDialog(_parent) 00064 , d( new KBuildSycocaProgressDialogPrivate(this) ) 00065 { 00066 connect(&d->m_timer, SIGNAL(timeout()), this, SLOT(_k_slotProgress())); 00067 setWindowTitle(_caption); 00068 setModal(true); 00069 setLabelText(text); 00070 setRange(0, 20); 00071 d->m_timeStep = 700; 00072 d->m_timer.start(d->m_timeStep); 00073 setAutoClose(false); 00074 } 00075 00076 KBuildSycocaProgressDialog::~KBuildSycocaProgressDialog() 00077 { 00078 delete d; 00079 } 00080 00081 void KBuildSycocaProgressDialogPrivate::_k_slotProgress() 00082 { 00083 const int p = m_parent->value(); 00084 if (p == 18) 00085 { 00086 m_parent->reset(); 00087 m_parent->setValue(1); 00088 m_timeStep = m_timeStep * 2; 00089 m_timer.start(m_timeStep); 00090 } 00091 else 00092 { 00093 m_parent->setValue(p+1); 00094 } 00095 } 00096 00097 void KBuildSycocaProgressDialogPrivate::_k_slotFinished() 00098 { 00099 m_parent->setValue(20); 00100 m_timer.stop(); 00101 QTimer::singleShot(1000, m_parent, SLOT(close())); 00102 } 00103 00104 00105 #include "kbuildsycocaprogressdialog.moc"
KDE 4.7 API Reference