1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// -*- c++ -*-
/*
* Copyright 2003 by Richard J. Moore, rich@kde.org
*/
#include <tdehtml_part.h> // this plugin applies to a tdehtml part
#include <kdebug.h>
#include "autorefresh.h"
#include <tdeaction.h>
#include <kinstance.h>
#include <kiconloader.h>
#include <tqmessagebox.h>
#include <tdelocale.h>
#include <tqtimer.h>
#include <kgenericfactory.h>
AutoRefresh::AutoRefresh( TQObject* parent, const char* name, const TQStringList & /*args*/ )
: Plugin( parent, name )
{
timer = new TQTimer( this );
connect( timer, TQT_SIGNAL( timeout() ), this, TQT_SLOT( slotRefresh() ) );
refresher = new TDESelectAction( i18n("&Auto Refresh"),
"reload", 0,
this, TQT_SLOT(slotIntervalChanged()),
actionCollection(), "autorefresh" );
TQStringList sl;
sl << i18n("None");
sl << i18n("Every 15 Seconds");
sl << i18n("Every 30 Seconds");
sl << i18n("Every Minute");
sl << i18n("Every 5 Minutes");
sl << i18n("Every 10 Minutes");
sl << i18n("Every 15 Minutes");
sl << i18n("Every 30 Minutes");
sl << i18n("Every 60 Minutes");
refresher->setItems( sl );
refresher->setCurrentItem( 0 );
}
AutoRefresh::~AutoRefresh()
{
}
void AutoRefresh::slotIntervalChanged()
{
int idx = refresher->currentItem();
int timeout = 0;
switch (idx) {
case 1:
timeout = ( 15*1000 );
break;
case 2:
timeout = ( 30*1000 );
break;
case 3:
timeout = ( 60*1000 );
break;
case 4:
timeout = ( 5*60*1000 );
break;
case 5:
timeout = ( 10*60*1000 );
break;
case 6:
timeout = ( 15*60*1000 );
break;
case 7:
timeout = ( 30*60*1000 );
break;
case 8:
timeout = ( 60*60*1000 );
break;
default:
break;
}
timer->stop();
if ( timeout )
timer->start( timeout );
}
void AutoRefresh::slotRefresh()
{
if ( !parent()->inherits("KParts::ReadOnlyPart") ) {
TQString title = i18n( "Cannot Refresh Source" );
TQString text = i18n( "<qt>This plugin cannot auto-refresh the current part.</qt>" );
TQMessageBox::warning( 0, title, text );
}
else
{
KParts::ReadOnlyPart *part = (KParts::ReadOnlyPart *) parent();
// Get URL
KURL url = part->url();
part->openURL( url );
}
}
K_EXPORT_COMPONENT_FACTORY( libautorefresh, KGenericFactory<AutoRefresh>( "autorefresh" ) )
#include "autorefresh.moc"
|