KWeather Konqueror sidebar revival

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/14/head
Mavridis Philippe 3 years ago
parent 9add97c815
commit 07171bc7a7
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -74,6 +74,7 @@ option( BUILD_KODO "Build kodo" ${BUILD_ALL} )
option( BUILD_KTEATIME "Build kteatime" ${BUILD_ALL} )
option( BUILD_KTUX "Build ktux" ${BUILD_ALL} )
option( BUILD_KWEATHER "Build kweather" ${BUILD_ALL} )
option( BUILD_KONQ_KWEATHER "Build kweather sidebar for Konqueror" ${BUILD_ALL} )
option( BUILD_KWORLDWATCH "Build kworldwatch" ${BUILD_ALL} )

@ -130,6 +130,18 @@ tde_add_kpart( kcm_weatherservice AUTOMOC
DESTINATION ${PLUGIN_INSTALL_DIR}
)
##### weather_sidebar (kpart) ####################
if( BUILD_KONQ_KWEATHER )
tde_import( konqueror )
tde_add_kpart( weather_sidebar AUTOMOC
SOURCES sidebarwidget.cpp dockwidget.cpp
weatherbar.cpp weatherbar.skel
weatherbutton.cpp weatherservice.stub
LINK tdeio-shared konqsidebarplugin-shared tdeutils-shared
DESTINATION ${PLUGIN_INSTALL_DIR}
)
endif( )
##### icons #####################################
@ -164,3 +176,17 @@ tde_create_translated_desktop(
DESTINATION ${SERVICES_INSTALL_DIR}
PO_DIR kweather-desktops
)
if( BUILD_KONQ_KWEATHER )
tde_create_translated_desktop(
SOURCE weatherbar.desktop
DESTINATION ${DATA_INSTALL_DIR}/konqsidebartng/entries
PO_DIR kweather-desktops
)
tde_create_translated_desktop(
SOURCE weatherbar_add.desktop
DESTINATION ${DATA_INSTALL_DIR}/konqsidebartng/add
PO_DIR kweather-desktops
)
endif( )

@ -179,7 +179,7 @@ void dockwidget::initDock()
m_lblWind->setMargin(0);
m_lblPres->setMargin(0);
TQBoxLayout *mainLayout = new TQBoxLayout(this, TQBoxLayout::TopToBottom);
TQBoxLayout *mainLayout = new TQBoxLayout(this, TQBoxLayout::LeftToRight);
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
mainLayout->addWidget(m_button, 0, TQt::AlignCenter);

@ -21,29 +21,75 @@
#include "sidebarwidget.h"
#include <tqscrollview.h>
#include <tqlayout.h>
#include <tqvbox.h>
#include <ksettings/dialog.h>
#include <ksettings/dispatcher.h>
#include <kcmultidialog.h>
sidebarwidget::sidebarwidget(TQWidget* parent, const char* name) :
sidebarwidgetbase(parent,name)
#include <kiconloader.h>
#include <tdetoolbar.h>
#include <tdeaction.h>
#include <tdelocale.h>
#include <dcopref.h>
sidebarwidget::sidebarwidget(TQWidget* parent, const char* name)
: TQWidget(parent,name)
{
view = new TQVBox(reportGrid->viewport());
reportGrid->addChild(view);
mainLayout = new TQVBoxLayout(this);
TDEToolBar *toolbar = new TDEToolBar(this);
toolbar->setLabel( i18n("Weather Sidebar") );
toolbar->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Minimum);
TDEAction *refresh = new TDEAction( i18n("Refresh"), SmallIcon("view-refresh"),
0, TQT_TQOBJECT(this), TQT_SLOT(slotRefresh()), this, "refresh" );
TDEAction *prefs = new TDEAction( i18n("Settings"), SmallIcon("configure"),
0, TQT_TQOBJECT(this), TQT_SLOT(slotConfigure()), this, "preferences" );
refresh->plug(toolbar);
prefs->plug(toolbar);
reportGrid = new TQScrollView(this);
reportGrid->setResizePolicy(TQScrollView::AutoOneFit);
layout = new TQVBoxLayout(reportGrid->viewport());
view = new TQVBox(reportGrid->viewport());
view->setSpacing(3);
layout->addWidget(view);
layout->addStretch();
mainLayout->addWidget(toolbar);
mainLayout->addWidget(reportGrid);
dcopCall = new DCOPRef( "KWeatherService", "WeatherService" );
}
sidebarwidget::~sidebarwidget()
{
}
TQWidget *sidebarwidget::viewport()
{
return view;
}
void sidebarwidget::addWidget(TQWidget *w, const TQString &s)
void sidebarwidget::slotRefresh()
{
w->setFixedWidth(reportGrid->visibleWidth ());
dcopCall->send("updateAll()");
}
TQWidget *sidebarwidget::viewport()
void sidebarwidget::slotConfigure()
{
return view;
if ( settingsDialog == 0 )
{
settingsDialog = new KCMultiDialog(0);
connect( settingsDialog, TQT_SIGNAL( configCommitted() ), this, TQT_SLOT( slotRefresh() ) );
settingsDialog->addModule( "kcmweatherservice.desktop" );
}
#include "sidebarwidget.moc"
settingsDialog->show();
settingsDialog->raise();
}
#include "sidebarwidget.moc"

@ -22,21 +22,36 @@
#ifndef __SIDEBARWIDGET_H__
#define __SIDEBARWIDGET_H__
#include <tqwidget.h>
#include <sidebarwidgetbase.h>
#include <tqvbox.h>
class TQVBox;
class TQVBoxLayout;
class TQScrollView;
class KCMultiDialog;
class DCOPRef;
class sidebarwidget : public sidebarwidgetbase
class sidebarwidget : public TQWidget
{
Q_OBJECT
public:
sidebarwidget(TQWidget* parent, const char* name = 0);
virtual ~sidebarwidget();
void addWidget(TQWidget *w, const TQString &s);
TQWidget *viewport();
TQScrollView *reportGrid;
TQVBoxLayout *mainLayout;
TQVBoxLayout *layout;
TQVBox *view;
private slots:
void slotRefresh();
void slotConfigure();
private:
DCOPRef *dcopCall;
KCMultiDialog *settingsDialog = 0;
};
#endif

@ -1,112 +0,0 @@
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<class>sidebarwidgetbase</class>
<author>ian reinhart geiser &lt;geiseri@kde.org&gt;</author>
<widget class="TQWidget">
<property name="name">
<cstring>Form1</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>480</height>
</rect>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQGroupBox" row="1" column="0">
<property name="name">
<cstring>GroupBox2</cstring>
</property>
<property name="title">
<string>Station Manager</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQLayoutWidget" row="0" column="0">
<property name="name">
<cstring>Layout1</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="KComboBox">
<property name="name">
<cstring>stationList</cstring>
</property>
</widget>
<widget class="KPushButton">
<property name="name">
<cstring>addStation</cstring>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</hbox>
</widget>
<spacer row="0" column="1">
<property name="name">
<cstring>Spacer4</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</grid>
</widget>
<widget class="TQGroupBox" row="0" column="0">
<property name="name">
<cstring>reportGroup</cstring>
</property>
<property name="title">
<string>Weather Report</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQScrollView" row="0" column="0">
<property name="name">
<cstring>reportGrid</cstring>
</property>
</widget>
</grid>
</widget>
</grid>
</widget>
<customwidgets>
<customwidget>
<class>QScrollView</class>
<header location="global">qscrollview.h</header>
<sizehint>
<width>25</width>
<height>25</height>
</sizehint>
<container>1</container>
<sizepolicy>
<hordata>3</hordata>
<verdata>3</verdata>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<pixmap>image0</pixmap>
</customwidget>
</customwidgets>
<layoutdefaults spacing="5" margin="5"/>
</UI>

@ -23,6 +23,7 @@
#include "dockwidget.h"
#include "sidebarwidget.h"
#include <tdeapplication.h>
#include <tqlabel.h>
#include <tqfont.h>
#include <tqlayout.h>
@ -32,7 +33,9 @@
#include <kdebug.h>
#include <tdeconfig.h>
#include <kstandarddirs.h>
#include <tdeglobalsettings.h>
#include <tdemessagebox.h>
#include <dcopclient.h>
#include <dcopref.h>
@ -50,32 +53,17 @@ KonqSidebarWeather::KonqSidebarWeather(TDEInstance* inst, TQObject* parent,
kdDebug() << "Get weatherstation list... " << endl;
if (!connectDCOPSignal(0,0,
"fileUpdate(TQString)",
"refresh(TQString)",false))
if (!(
connectDCOPSignal(0, 0, "fileUpdate(TQString)", "refresh(TQString)", false) &&
connectDCOPSignal(0, 0, "stationAdded(TQString)", "updateWidgets()", false) &&
connectDCOPSignal(0, 0, "stationRemoved(TQString)", "updateWidgets()", false)
))
kdDebug() << "Could not attach signal..." << endl;
else
kdDebug() << "attached dcop signals..." << endl;
DCOPRef dcopCall( "KWeatherService", "WeatherService" );
DCOPReply reply = dcopCall.call("listStations()", true );
if ( reply.isValid() ) {
TQStringList replyList = reply;
for(int i = 0; i < replyList.size(); i++)
{
dockwidget *d = new dockwidget(m_container->viewport(), replyList[i].latin1());
m_container->addWidget(d, replyList[i].latin1());
d->resizeView(80,48);
d->show();
m_widgets.insert(replyList[i], d);
dcopCall.send("update(TQString)", replyList[i]);
}
}
timeOut = new TQTimer(this, "timeOut" );
timeOut->changeInterval(15*60000);
connect(timeOut, TQT_SIGNAL(timeout()), this, TQT_SLOT(update()));
// m_widgets.append(new dockwidget(widgetParent));
updateWidgets(true);
}
@ -102,15 +90,16 @@ void KonqSidebarWeather::refresh(TQString stationID)
kdDebug() << "refresh " << stationID << endl;
if(m_widgets.find(stationID))
{
/* These updates are seemingly now handled by dockwidget itself
DCOPRef dcopCall( "KWeatherService", "WeatherService" );
m_widgets[stationID]->setWeatherIcon(dcopCall.call("currentIcon(TQString)", stationID ,true ));
m_widgets[stationID]->setTemperature(dcopCall.call("temperature(TQString)", stationID,true ));
m_widgets[stationID]->setPressure(dcopCall.call("pressure(TQString)", stationID,true ));
m_widgets[stationID]->setWind(dcopCall.call("wind(TQString)", stationID,true ));
*/
m_widgets[stationID]->showWeather();
}
else
update();
}
void KonqSidebarWeather::handleURL(const KURL& url)
@ -125,26 +114,107 @@ void KonqSidebarWeather::handlePreviewOnMouseOver(const KFileItem& item)
{
}
void KonqSidebarWeather::update()
void KonqSidebarWeather::updateWidgets( bool firstTime )
{
kdDebug() << "updating station widgets" << endl;
timeOut->stop();
DCOPRef dcopCall( "KWeatherService", "WeatherService" );
DCOPReply reply = dcopCall.call("listStations()", true );
// KWeatherService might not be active at this point
if( !reply.isValid() ) {
kdDebug() << "Starting KWeatherService" << endl;
if( !startWeatherService() ) {
KMessageBox::sorry(0, i18n("Could not start the weather service!"));
return;
}
reply = dcopCall.call("listStations()", true );
}
if ( reply.isValid() ) {
TQStringList replyList = reply;
// Check for new cities
for(int i = 0; i < replyList.size(); i++)
{
if(!m_widgets.find(replyList[i]))
{
dockwidget *d = new dockwidget(m_container->viewport(), replyList[i].latin1());
m_container->addWidget(d, replyList[i].latin1());
TQLabel *city = new TQLabel(
dcopCall.call("stationName(TQString)", replyList[i], true),
m_container->viewport()
);
city->setPaletteBackgroundColor(TDEGlobalSettings::highlightColor());
city->setPaletteForegroundColor(TDEGlobalSettings::highlightedTextColor());
dockwidget *d = new dockwidget(replyList[i], m_container->viewport());
d->resizeView(TQSize(d->width(), 48));
city->show();
d->show();
m_labels.insert(replyList[i], city);
m_widgets.insert(replyList[i], d);
}
dcopCall.send("update(TQString)", replyList[i]);
}
// Check for removed cities
TQDictIterator<dockwidget> it(m_widgets);
for(; it.current(); ++it)
{
TQString current(it.currentKey());
if(!replyList.contains(current))
{
m_widgets[current]->~dockwidget();
m_labels[current]->~TQLabel();
m_widgets.remove(current);
m_labels.remove(current);
}
}
} else {
KMessageBox::sorry(0, i18n("The weather service is unreachable!"));
}
if( firstTime )
timeOut->start(15*60000);
else
{
timeOut->changeInterval(15*60000);
connect(timeOut, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateWidgets()));
}
}
bool KonqSidebarWeather::startWeatherService()
{
TQByteArray data, replyData;
TQCString replyType;
TQDataStream arg(data, IO_WriteOnly);
arg << TQString("KWeatherService") << TQStringList();
if ( !kapp->dcopClient()->call(
"tdelauncher", "tdelauncher",
"start_service_by_name(TQString,TQStringList)",
data, replyType, replyData) ) {
kdDebug() << "Cannot start weather service: tdelauncher call failed." << endl;
return false;
}
TQDataStream reply(replyData, IO_ReadOnly);
if ( replyType != "serviceResult" )
{
kdDebug() << "Cannot start weather service: unknown reply type by tdelauncher." << endl;
return false;
}
int result;
TQCString dcopName;
TQString error;
reply >> result >> dcopName >> error;
if (result != 0)
{
kdDebug() << "Cannot start weather service: " << error.local8Bit().data() << endl;
return false;
}
return true;
}
extern "C"
@ -159,8 +229,8 @@ extern "C"
TQMap<TQString, TQString>* map)
{
map->insert("Type","Link");
map->insert("Icon","weather_sidebar");
map->insert("Name",i18n("Sidebar Weather Report"));
map->insert("Icon","kweather");
map->insert("Name",i18n("Weather"));
map->insert("Open","false");
map->insert("X-TDE-KonqSidebarModule","weather_sidebar");
fn->setLatin1("weatherbar%1.desktop");

@ -1,8 +1,7 @@
[Desktop Entry]
Type=Link
URL=
Icon=weather_sidebar
Name=Sidebar Weather Report
Icon=kweather
Name=Weather
Open=false
X-TDE-KonqSidebarModule=weather_sidebar

@ -33,6 +33,7 @@
class dockwidget;
class sidebarwidget;
class TQLabel;
class KonqSidebarWeather: public KonqSidebarPlugin, virtual public DCOPObject
{
@ -51,15 +52,18 @@ public:
k_dcop:
virtual void refresh(TQString);
public slots:
virtual void updateWidgets( bool firstTime = false );
protected:
virtual void handleURL(const KURL &url);
virtual void handlePreview(const KFileItemList& items);
virtual void handlePreviewOnMouseOver(const KFileItem& item);
private slots:
void update();
private:
bool startWeatherService();
TQDict <TQLabel> m_labels;
TQDict <dockwidget> m_widgets;
sidebarwidget *m_container;
TQTimer *timeOut;

@ -1,8 +1,7 @@
[Desktop Entry]
Type=Link
URL=
Icon=weather_sidebar
Name=Sidebar Weather Report
Icon=kweather
Name=Weather
Open=false
X-TDE-KonqSidebarAddModule=weather_sidebar

@ -192,12 +192,16 @@ void WeatherService::removeStation(const TQString &stationID)
{
m_weatherLib->remove(stationID);
saveSettings();
emit stationRemoved(stationID);
kdDebug() << "KWeatherService: station removed: " << stationID << endl;
}
void WeatherService::addStation(const TQString &stationID)
{
m_weatherLib->update(stationID);
saveSettings();
emit stationAdded(stationID);
kdDebug() << "KWeatherService: station added: " << stationID << endl;
}
void WeatherService::exit()
@ -339,5 +343,4 @@ TQString WeatherService::civilTwilightEnd(const TQString &stationID)
}
#include "weatherservice.moc"

@ -51,6 +51,7 @@ class WeatherService : public TQObject, public DCOPObject
void fileUpdating(TQString);
void fileUpdate(TQString);
void stationRemoved(TQString);
void stationAdded(TQString);
k_dcop:
TQString temperature(const TQString &stationID);

Loading…
Cancel
Save