knewstuffbutton.cpp
00001 /* 00002 Copyright (c) 2004 Aaron J. Seigo <aseigo@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 as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include <kiconloader.h> 00021 #include <tdelocale.h> 00022 00023 #include "downloaddialog.h" 00024 #include "knewstuffbutton.h" 00025 #include "knewstuffbutton.moc" 00026 00027 namespace KNS 00028 { 00029 00030 Button::Button(const TQString& what, 00031 const TQString& providerList, 00032 const TQString& resourceType, 00033 TQWidget* parent, const char* name) 00034 : KPushButton(parent, name), 00035 d(0), 00036 m_providerList(providerList), 00037 m_type(resourceType), 00038 m_downloadDialog(0) 00039 { 00040 setButtonText(what); 00041 init(); 00042 } 00043 00044 Button::Button(TQWidget* parent, const char* name) 00045 : KPushButton(parent, name), 00046 d(0), 00047 m_downloadDialog(0) 00048 { 00049 setButtonText(i18n("Download New Stuff")); 00050 init(); 00051 } 00052 00053 void Button::init() 00054 { 00055 setIconSet(SmallIconSet("knewstuff")); 00056 connect(this, TQT_SIGNAL(clicked()), TQT_SLOT(showDialog())); 00057 } 00058 00059 void Button::setButtonText(const TQString& what) 00060 { 00061 setText(i18n("Download New %1").arg(what)); 00062 } 00063 00064 void Button::setProviderList(const TQString& providerList) 00065 { 00066 m_providerList = providerList; 00067 } 00068 00069 void Button::setResourceType(const TQString& resourceType) 00070 { 00071 m_type = resourceType; 00072 } 00073 00074 void Button::showDialog() 00075 { 00076 emit aboutToShowDialog(); 00077 00078 if (!m_downloadDialog) 00079 { 00080 m_downloadDialog = new DownloadDialog(0, this); 00081 } 00082 00083 m_downloadDialog->setType(m_type); 00084 m_downloadDialog->load(m_providerList); 00085 00086 m_downloadDialog->exec(); // TODO: make non-modal? 00087 emit dialogFinished(); 00088 } 00089 00090 }