By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release. View | Details | Raw Unified | Return to bug 2127
Collapse All | Expand All

(-)tdewebdev/configure.in.in (-8 / +2 lines)
Lines 241-260 Link Here
241
  CXXFLAGS="$CXXFLAGS -DENABLE_CVSSERVICE"
241
  CXXFLAGS="$CXXFLAGS -DENABLE_CVSSERVICE"
242
fi
242
fi
243
243
244
#check for KNewStuffSecure headers
244
#check for TDENewStuffSecure headers
245
KNEWSTUFF_INCLUDES=""
245
KNEWSTUFF_INCLUDES=""
246
LIB_KNEWSTUFF="-lknewstuff"
246
LIB_KNEWSTUFF="-lknewstuff"
247
KDE_CHECK_HEADER(knewstuff/knewstuffsecure.h, [knewstuffsecure_h="found"], [knewstuffsecure_h="none"])
247
KDE_CHECK_HEADER(tdenewstuff/knewstuffsecure.h, [knewstuffsecure_h="found"], [knewstuffsecure_h="none"])
248
AM_CONDITIONAL(include_knewstuff, test "$knewstuffsecure_h" != "found")
248
AM_CONDITIONAL(include_knewstuff, test "$knewstuffsecure_h" != "found")
249
if test "$knewstuffsecure_h" != "found"; then
250
  KNEWSTUFF_INCLUDES='-I$(top_srcdir)/lib/compatibility'
251
  LIB_KNEWSTUFF='$(top_builddir)/lib/compatibility/knewstuff/libknewstuff.la'
252
fi
253
AC_SUBST(KNEWSTUFF_INCLUDES)
249
AC_SUBST(KNEWSTUFF_INCLUDES)
254
AC_SUBST(LIB_KNEWSTUFF)
250
AC_SUBST(LIB_KNEWSTUFF)
255
251
256
257
258
AC_ARG_ENABLE(editors, [  --enable-editors        Enable selection of other editors aside of Kate],
252
AC_ARG_ENABLE(editors, [  --enable-editors        Enable selection of other editors aside of Kate],
259
[enable_editors=$enableval], [enable_editors="no"])
253
[enable_editors=$enableval], [enable_editors="no"])
260
254
(-)tdewebdev/lib/compatibility/Makefile.am (-6 / +1 lines)
Lines 2-13 Link Here
2
KMDI_SUBDIR = tdemdi
2
KMDI_SUBDIR = tdemdi
3
endif
3
endif
4
4
5
if include_knewstuff
5
SUBDIRS = $(KMDI_SUBDIR)
6
KNEWSTUFF_SUBDIR = knewstuff
7
endif
8
9
10
SUBDIRS = $(KMDI_SUBDIR) $(KNEWSTUFF_SUBDIR)
11
6
12
#enable the below when there is something in the compatibility lib
7
#enable the below when there is something in the compatibility lib
13
#noinst_LTLIBRARIES = libcompat.la
8
#noinst_LTLIBRARIES = libcompat.la
(-)tdewebdev/lib/compatibility/knewstuff/Makefile.am (-13 lines)
Lines 1-13 Link Here
1
AM_CPPFLAGS = -I$(srcdir)/.. $(all_includes)
2
3
METASOURCES = AUTO
4
5
noinst_LTLIBRARIES = libknewstuff.la
6
7
libknewstuff_la_LDFLAGS = $(all_libraries)
8
libknewstuff_la_LIBADD  = $(LIB_TDEIO)
9
libknewstuff_la_SOURCES = engine.cpp entry.cpp downloaddialog.cpp \
10
  uploaddialog.cpp providerdialog.cpp provider.cpp knewstuff.cpp \
11
  knewstuffgeneric.cpp knewstuffsecure.cpp security.cpp
12
13
KDE_ICON=AUTO
(-)tdewebdev/lib/compatibility/knewstuff/cr16-action-knewstuff.png (-5 lines)
Lines 1-5 Link Here
1
‰PNG
2
3
IHDRóÿa	pHYsÒÝ~ügAMA±Ž|ûQ“ cHRMz%€ƒùÿ€éu0ê`:˜o’_ÅF<IDATxÚb`ÀΤ™Þa|jˆ	fa#S²p© &<†Çhh2먁ٸNXXÿ(K3ð*k1°ó²]!€M@1ár>¿ª²ÃŸ¯?^0kȀ4`S@Œ@Å	@ZÊçbfÖ?ÊAμrb`Á_¿0ÜZ¾ãÃÏÏÿ/ é@Œ—
4
ôþËڊ00sÝÍÏÀ+ò	L3°ñÿÿPuÿ!øû#8ûï÷¾b ¦_ߨŸŸþÀÀ%ôŒWèdv ?€j^Bñ(æ`c``ûÔ|›áÖ¦—3'#ÔÏÌlæ«yßàg ÄÀÀȂ°léw†¿Ÿ¾½üÃpk«ú‡¿¿XMfÞ@ŒÈÇÂñg½¼óå÷XcæÛk.†[뀚²85ƒÃ €à±øóƒÅñÕeq.¬øãcA æB˜f ôhTà”þÆÀÀÉÁ ÷ýe€óyT?Ôè#k txÕ>Ã5ÿzÅÊðí0ô| Å«ù™==ºö¼Ú@[þ10¼:$Ìp}‘úƒë56Ü]-?f`00è½å
Xºa ¸d¿9€4ß]¨Èðx—†?¿9
Mæ]üpG$ðr—ö‡çéD
ì
5
xæ ”Xà’úzþç;Ö¿³&šÌ>³-y0üÿ7ŸKê[À·g܍@ù8@€›TÁyý¥¤IEND®B`‚
(-)tdewebdev/lib/compatibility/knewstuff/cr32-action-knewstuff.png (-8 lines)
Lines 1-8 Link Here
1
‰PNG
2
3
IHDR  szzô	pHYsÒÝ~ügAMA±Ž|ûQ“ cHRMz%€ƒùÿ€éu0ê`:˜o’_ÅF)IDATxÚbüÿÿ?Ã@€bŒŒŒ$k¼YÏàÀÄİÿï?†@݊êH5äy€b"ÛéLùRBB@v¹ÆY¸ÝÌ ÀÂÌÀ£ŸÎ   A†|r@ä…#Ðr^ -íËÀªÇÀÁÁ p»…Á€£ˆ,021øóKßK–AĊA@,FV(ɸ×Á ÀÆÊÀ.mÃÀðçXŒ[œ˜ Èq@‘ì`|ps’Þ@|f`øý™IĔ—‡Aà~'é‰ €˜Èþxq.°åàPÐaàG
©æIxØÇ ÀÂÊ`À&i	± Žà¶dʀԐb&@1‘üõ|ÀÇ  ÆÀðhñ_$,lÀÀÃQóhñŽ FPiôd2£í€(¢ôAÖ ©ËqC]P͊	ÿHŠaàßó­Ÿîgøý!ûçÐ}Pì¼Ä Ró‚LÞÿB€;àÙ4Æÿ<@ë€)™•ªŒMŒ…ƒ™ÊçJò30ðê£XŠÁþþˆaÊý|táOˆC¼fxóä'ƒXêF€× ‹9…ùXåB˜y±[ðJüÿŒÝb`‚`ljþƒæëe†ïož0üù
	€bT
4
‰ï~êçÿ=W€C¿<†@Wq㷝ýšÿ@‹>e`ør‘áãã/ß>2\¦G@£T>Ÿ,JÖóI0(p‰€|"Œi –¦,üàrÐï@üœá×3†ÿ¿3||ÂÀðã3à\¡dÐÝw¼˜LxŒû9xv32CÍc&oa`¨p1/ÂfP„™ÐTöÿ;ÄÞñ;„sþ20¼¿tËw†©‰ÈÕ1@¡8^Íe˜ÏÂɐÊmpG	þ|&ùÛ`G$Š%}Ö ¬×ó€–Ïç׀zäPAùé6ǀ–'1lÀÖ  œ7YÖè20±“ØÚÆÊûÀxþÍà(’IñØ@xKB ÆŒÿ&þe_VÒð_`Â꽀Ër ‚E%3ƒ>#Ô`R›ÀœÄĆTºâÄDDíçÀ"ŠÃ§ ùÊ%ØåYçÃ
5
üŽ ¼ø¸ŠÁhˆ†á ¿AðZ²3`:”s	Uф×L ߋ@#
6
†A–â¿ úŠA‚GPÕ²HAÌÀg@1~{fQ4Ÿ‡Ðô·Ë@·œÂsPÉ	
?õ 2X¢|YR³¢€"äfq¨LË+¼Ÿ·ü•çl‚Þ0Lø~XÂBæ74@Ñ 
7
iÆá² €p:àÛff1 Ëaùä'¤Ôý	´èï[†Œl†<€øwC!P…ãÏë~߇:à'ı̐"ݗ=Ą'þ
˜E A
8
4ì/°"ùu\°rù3$rù¡vŀüÀBËðï+†	¿Îûb̂øÓ@1àêœþÜÎ0ÿïK†ÿÿÞ+Ó#ÿncØÿcî¸D@u?·2ÜÿshüG þCÿqÙ
@LxÚþk°¿çÀ)¼Ý‹Á‘˸(PÝ`°þ{Á0áÏ9p–ÅYã@wÏ1ŒžÛÓÜpIEND®B`‚
(-)tdewebdev/lib/compatibility/knewstuff/cr64-action-knewstuff.png (-22 lines)
Lines 1-22 Link Here
1
‰PNG
2
3
IHDR@@ªiqÞ	pHYsÒÝ~ügAMA±Ž|ûQ“ cHRMz%€ƒùÿ€éu0ê`:˜o’_ÅF¾IDATxÚb`@p£ŽÁˆÒ
Ä8 ¯g0RûX*Ô¨ÑÈÐ0n ¦
4
õ~ffII0¿þfƒÃ@¸ €è@*}ì (ÄÀÀÇÏÀ +O‡ñD÷`ddÈb>>¨€.àç‹'Üj„g	º€b€ôÀLö¬¬@¶^+ÁÏÀÍM@9z; €è·›€1­‹}	W¹0H€€R½ €èÀùäa~-`	(ÎÀ Äc`0¸ÝBßj €˜èœÿÁɟ…ÈQ†Å¿_¼*ÀA“A@,Ê	tMD·¸Ó
5
¬æ€É_€* fÏÀð÷Kû…“‹þå@1Ñ1öãA1ÌÍ
ò¼#°øg‡¤–ò«áå«S¸ÛF¿@ úe`̂<ªöDmžaP`ˆÙ1pS3X-ÝÚD—¸×ÁŒYÁ@ÄêùŸPdK¸ƒ¤TVõÐ¥M@LtŠ}PéÆ
6
 G!Éÿ'j*6×
7
¼ˆ6A=œ@4€û] yœü…Í0=p߀•RfÐ#ˆ)T 	pqI`! dŒÝó @†°60ðhí8€¢ycÒØóc€)nσh6`¶çV`àᆶ	è
8
ˆ¦ð X“?Øó  hˆÛóÿ m`ó˜…ÒM¦G9@L4Ž}Pé)üX€„€.nσð ЂÐT 𰗶m€¢m&aP½ná‰Z@<Ç?l”63X-¨‡H6@Ñ,õƒ{~à
äaܞGÐëႶ	@fÑʝÄBUOO÷ä`¸\¢ƒÚþì‚ÀL-ñúÿ#¤xÕÁzøß3|ÿ£çf/Ê<DÒðˆ/à*~ä
9
ãf€Â}<î…>r«Ì‰-•ÇLZÀ´%(Lþ ¶¿t4ÐSÚø=¾Þ:fÃo`¢øðށáçªÅ(Ð@Ó(›Ïp €ÀðdCÀHŒÕgeƒæO(uq‘=’ge‡6|āe¿’ÿã1MîË
†—›€IÕ÷?¿c×
L)¿a—‰ƒä‘ôz^ €ŸL{ú>ȱ\¼1B=Ï'¬À,Ijfá”&[ -O¼‡áÂHâ ϾL·PÕüùÄÉJ?¾20¼}f:¨®¢%€Ù”[ZF%›Rh35‚’©94þ"ìI|5Õb=âÍùñ»¹ï“Âk†H™ €X¡Œß¿ng‚zX*ÕSx“.ºø/ÌB(sˆ´ã?ê9ÄÐÒÿ†wû
­7?¾10|z®]µ_ °÷ŸMc8*̸…5H/(†ù€ÍV.
ò@²8ìU±_€^ûrÌýÌ1 Iÿ0á8Jg3\ X€Jóõ 	P6à—‚rl@¯– ?	S(äÚªn¿Ð¯×¡U/0ցÿú¬TJeAªI€B©ŸOg˜jƒJp~i`B€•î,BÀÔ 	LZÊTöä<JÈ0ë°tûvX܇{üÿ_ˆçA±TräyÉLp£ð|&¸2TöË36nä	X5°+Xn2P7æÿ“YFü^¿žë¶‡àE
10
XÚ½†ÅoH-º@2!];@a~1:{ìŒðÉk2Alµ$‹°ˆ@²È:f‡À’ì°uôûc€uýÇ'@úØØB‰t†	ØÔÎéñ³ÀÕ#¨\0Ÿ,¡Fµ03ÌÀB”‰ƒz…Ú_`æýû‚Aÿ÷¯S@žÚðùϐ(‘nFc„w}ÀËÙàÂT.°ûô‚*Àꃙ”®hœ›(ŒÐ–#jàÀ]ýÉÏ? 
 Gÿ“ÖþŸOÀåsGñTœý0 ¢H¼œÃЬ7ëAE¿"¤k?Á÷WÀï)8·€<(ž‚ßó @D¯y5\8öS€°\à\žÿ,¼…vv€u¼X2¢¤Çˆ¤%2À@0`„”
11
\Àò„üÿLòÀüþû38Ù/–…bIÄyˆä5B¯çƒËP
aÀdñ(‘X.P€FÔ>ÝßÀžŸ šÈPHªDö"©7 &PyÀ§Iÿ@5p>\†´vA%½Hî’ ŠV‰½Y,泋S‚2}à°íóõ!ÔóñäyˆâeroSC‚%}àËM`ðÃáXEJÌ ŠÇ!xD€jôÌ ,ÀH…UŽÄDäAÀÈý¥f‡¾Â»¥”-© Š4ôÍÂ5‰Ž˜E>}FÑÄ	@Q–ƒ§¾@Ž¡gìƒ0¨»ÁÈ
12
Nö”ø €X(,¡Ã¤%¨£òJƒ<EFóšU<Úå@‰ˆ‰ÂäoJ†ð ƒ<ýT”1¨jރÖI$˜Ã*™?ü¸’ü@ &JS¸£ÇNBòý˙ÓAÿÿGB6b€­&!;ˆìø´¼òÃ4@t¬›®¡lfhDÆÿ¡òˆ3‰hdþП\±o
13
}fa"cäù¯D¨¹èdtsYÄ nù¼†¼EUÄDAþw`„¡Øú
14
-ðXHÀß ú˜Í,m‘™
ˆ…’‰šÿña~…&i´qÌ;ÐA h¡È
15
lذ*@«6ø(´ äÅÝh‡8l ÕÄBQKþ¸ª¹/PO ©ùû˜n<ïŸò¶ÿýÁáÏvu rA,æðb·Ôü¹ãï;òR@‘ÕšþºlÙ~v åâx<ÿ5Ö߆ÇKp°ƒÊûDîDŒÍ,RõÀ`šÉª„F„»”{ ü¾
Đ¹SE ™Hñ@1‘û 1‰`ɗ°dπ(¨@£Ø?/=²bzšìP”ä
16
äOŠå€Ôý<Ô÷	©L`FÊNèå€$Ù.ˆ‰ìüÏ
ÍÿèžÿŽTÍñ`|ü<ºúÀÈÄPÈíÏÄX‡¬€â€Ø¤hԇŸW ±ž@®M~¡U‡9F2šÅDn8€
17
Ôt-¹¡­9ÐrŸ_@ÿyŽõ@qG.?ì“謔X€ÊŒ_§€©á’§Avý`@™J`‚†$—Dr|ßMþÂh¥5R¬ü}䞆$}`¬5rù2ñRìªÄŽ@»
18
ÿÿcøðëК[Ðr…jçwD 0K€ÅÀî#9±ªv˜„ ?¡¿/BÊÈð¨Î‘Ó‡²
‘@ý€æKû_"¥F¤,÷âh÷˜¤ Ҁ	Ø5?9¡‡ÆÈÿXÿÿë@I˜Ã<K1šóˆ!©á/Ç?À@þ{š
19
þC²¨ýviå@1‘Q€cÿ'¢š9æ÷%°ƒ>å9¼ø•ÐLpj`¥Ð¼èHÀÃÊ ð¢+v€"=€úl_!Éî?°®ÿª®^€Cþ(ÖÙ=Io‘€æ?bpjøŸËÀ¸tÃH`02ðDN
20
Xø4I{ˆÏCç.Žaó`pd÷ ­BQ@x@k
21
&†
ÿ€í†¿ÁYïP¬‘sˆ¬–àï](ÍV7úy‡{@£
22
@w\æTágÉ`증IEND®B`‚
(-)tdewebdev/lib/compatibility/knewstuff/downloaddialog.cpp (-628 lines)
Lines 1-628 Link Here
1
/*
2
    This file is part of KNewStuff.
3
    Copyright (c) 2003 Josef Spillner <spillner@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include "downloaddialog.h"
22
#include "downloaddialog.moc"
23
24
#include <tdelocale.h>
25
#include <ktabctl.h>
26
#include <tdelistview.h>
27
#include <kdebug.h>
28
#include <tdeio/job.h>
29
#include <tdeio/netaccess.h>
30
#include <tdemessagebox.h>
31
#include <kurl.h>
32
#include <tdeconfig.h>
33
#include <tdeapplication.h>
34
#include <kiconloader.h>
35
36
#include <knewstuff/entry.h>
37
#include <knewstuff/knewstuffgeneric.h>
38
#include <knewstuff/engine.h>
39
40
#include <tqlayout.h>
41
#include <tqpushbutton.h>
42
#include <tqdom.h>
43
#include <tqlabel.h>
44
#include <tqtextbrowser.h>
45
#include <tqtimer.h> // hack
46
47
using namespace KNS;
48
49
class NumSortListViewItem : public TDEListViewItem
50
{
51
  public:
52
  NumSortListViewItem( TQListView * parent, TQString label1, TQString label2 = TQString(), TQString label3 = TQString(), TQString label4 = TQString(), TQString label5 = TQString(), TQString label6 = TQString(), TQString label7 = TQString(), TQString label8 = TQString() )  :
53
  TDEListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )  
54
  {
55
  }
56
57
  TQString key(int col, bool asc) const {
58
    if (col == 2)
59
    {
60
      
61
      TQString s;
62
      s.sprintf("%08d", text(col).toInt());
63
      return s;
64
    }
65
    return TDEListViewItem::key( col, asc );
66
  }
67
};
68
69
// BEGIN deprecated for KDE 4
70
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *)
71
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
72
  KDialogBase::Close, KDialogBase::Close)
73
{
74
  init(engine);
75
}
76
77
DownloadDialog::DownloadDialog(TQWidget *)
78
: KDialogBase(KDialogBase::IconList, i18n("Get Hot New Stuff"),
79
  KDialogBase::Close, KDialogBase::Close)
80
{
81
  init(0);
82
}
83
84
void DownloadDialog::open(TQString type)
85
{
86
  DownloadDialog d;
87
  d.setType(type);
88
  d.load();
89
  d.exec();
90
}
91
// END deprecated for KDE 4
92
93
DownloadDialog::DownloadDialog(Engine *engine, TQWidget *, const TQString& caption)
94
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
95
  KDialogBase::Close, KDialogBase::Close)
96
{
97
  init(engine);
98
}
99
100
DownloadDialog::DownloadDialog(TQWidget *, const TQString& caption)
101
: KDialogBase(KDialogBase::IconList, (caption.isNull() ? i18n("Get Hot New Stuff") : caption),
102
  KDialogBase::Close, KDialogBase::Close)
103
{
104
  init(0);
105
}
106
107
void DownloadDialog::init(Engine *engine)
108
{
109
  resize(700, 400);
110
111
  m_engine = engine;
112
  m_page = NULL;
113
114
  connect(this, TQT_SIGNAL(aboutToShowPage(TQWidget*)), TQT_SLOT(slotPage(TQWidget*)));
115
116
  if(!engine)
117
  {
118
    m_loader = new ProviderLoader(this);
119
    connect(m_loader, TQT_SIGNAL(providersLoaded(Provider::List*)), TQT_SLOT(slotProviders(Provider::List*)));
120
  }
121
}
122
123
DownloadDialog::~DownloadDialog()
124
{
125
}
126
127
void DownloadDialog::load()
128
{
129
  m_loader->load(m_filter, m_providerlist);
130
}
131
132
void DownloadDialog::load(TQString providerList)
133
{
134
  m_loader->load(m_filter, providerList);
135
}
136
137
void DownloadDialog::clear()
138
{
139
  TQMap<TQWidget*, TQValueList<TDEListView*>* >::Iterator it;
140
  for(it = m_map.begin(); it != m_map.end(); ++it)
141
  {
142
    TQValueList<TDEListView*> *v = it.data();
143
    kdDebug() << "clear listviews in " << v << endl;
144
    if(v)
145
    {
146
      (*(v->at(0)))->clear();
147
      (*(v->at(1)))->clear();
148
      (*(v->at(2)))->clear();
149
150
      //delete (*it);
151
    }
152
153
    delete it.key();
154
  }
155
  m_map.clear();
156
}
157
158
void DownloadDialog::slotProviders(Provider::List *list)
159
{
160
  Provider *p;
161
  /*TQFrame *frame;*/
162
163
  for(p = list->first(); p; p = list->next())
164
  {
165
    kdDebug() << "++ provider ++ " << p->name() << endl;
166
167
    if(!m_filter.isEmpty())
168
      loadProvider(p);
169
    else
170
      addProvider(p);
171
    /*if(p == list->getFirst())
172
      slotPage(m_frame);*/ // only if !qtbug
173
  }
174
}
175
176
void DownloadDialog::addProvider(Provider *p)
177
{
178
  TQFrame *frame;
179
  KTabCtl *ctl;
180
  TQWidget *w_d, *w_r, *w_l;
181
  TQWidget *w2;
182
  TDEListView *lvtmp_r, *lvtmp_d, *lvtmp_l;
183
  TQTextBrowser *rt;
184
  TQString tmp;
185
  int ret;
186
  TQPixmap pix;
187
188
  if(m_map.count() == 0)
189
  {
190
    frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap(""));
191
    delete frame;
192
  }
193
194
  kdDebug() << "addProvider()/begin" << endl;
195
196
  ret = true;
197
  if(!p->icon().isValid()) ret = false;
198
  else ret = TDEIO::NetAccess::download(p->icon(), tmp, this);
199
  if(ret) pix = TQPixmap(tmp);
200
  else pix = TDEGlobal::iconLoader()->loadIcon("knewstuff", TDEIcon::Panel);
201
  frame = addPage(p->name(), p->name(), pix);
202
  m_frame = frame;
203
204
  w2 = new TQWidget(frame);
205
  w_d = new TQWidget(frame);
206
  w_r = new TQWidget(frame);
207
  w_l = new TQWidget(frame);
208
209
  ctl = new KTabCtl(frame);
210
  ctl->addTab(w_r, i18n("Highest Rated"));
211
  ctl->addTab(w_d, i18n("Most Downloads"));
212
  ctl->addTab(w_l, i18n("Latest"));
213
214
  m_curtab = 0;
215
  connect(ctl, TQT_SIGNAL(tabSelected(int)), TQT_SLOT(slotTab(int)));
216
217
  TQHBoxLayout *box = new TQHBoxLayout(frame);
218
  box->add(ctl);
219
220
  lvtmp_r = new TDEListView(w_r);
221
  lvtmp_r->addColumn(i18n("Name"));
222
  lvtmp_r->addColumn(i18n("Version"));
223
  lvtmp_r->addColumn(i18n("Rating"));
224
  lvtmp_r->setSorting(2, false);
225
226
  lvtmp_d = new TDEListView(w_d);
227
  lvtmp_d->addColumn(i18n("Name"));
228
  lvtmp_d->addColumn(i18n("Version"));
229
  lvtmp_d->addColumn(i18n("Downloads"));
230
  lvtmp_d->setSorting(2, false);
231
232
  lvtmp_l = new TDEListView(w_l);
233
  lvtmp_l->addColumn(i18n("Name"));
234
  lvtmp_l->addColumn(i18n("Version"));
235
  lvtmp_l->addColumn(i18n("Release Date"));
236
  lvtmp_l->setSorting(2, false);
237
238
  connect(lvtmp_r, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
239
  connect(lvtmp_d, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
240
  connect(lvtmp_l, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelected()));
241
242
  rt = new TQTextBrowser(frame);
243
  rt->setMinimumWidth(150);
244
245
  TQPushButton *in = new TQPushButton(i18n("Install"), frame);
246
  TQPushButton *de = new TQPushButton(i18n("Details"), frame);
247
  in->setEnabled(false);
248
  de->setEnabled(false);
249
250
  box->addSpacing(spacingHint());
251
  TQVBoxLayout *vbox = new TQVBoxLayout(box);
252
  vbox->add(rt);
253
  vbox->addSpacing(spacingHint());
254
  vbox->add(de);
255
  vbox->add(in);
256
257
  connect(in, TQT_SIGNAL(clicked()), TQT_SLOT(slotInstall()));
258
  connect(de, TQT_SIGNAL(clicked()), TQT_SLOT(slotDetails()));
259
260
  TQVBoxLayout *box2 = new TQVBoxLayout(w_r);
261
  box2->add(lvtmp_r);
262
  TQVBoxLayout *box3 = new TQVBoxLayout(w_d);
263
  box3->add(lvtmp_d);
264
  TQVBoxLayout *box4 = new TQVBoxLayout(w_l);
265
  box4->add(lvtmp_l);
266
267
  TQValueList<TDEListView*> *v = new TQValueList<TDEListView*>;
268
  *v << lvtmp_r << lvtmp_d << lvtmp_l;
269
  m_map[frame] = v;
270
  m_rts[frame] = rt;
271
  TQValueList<TQPushButton*> *vb = new TQValueList<TQPushButton*>;
272
  *vb << in << de;
273
  m_buttons[frame] = vb;
274
  m_providers[frame] = p;
275
276
  kdDebug() << "addProvider()/end; lvtmp_r = " << lvtmp_r << endl;
277
278
  if(m_engine) slotPage(frame);
279
280
  TQTimer::singleShot(100, this, TQT_SLOT(slotFinish()));
281
}
282
283
void DownloadDialog::slotResult(TDEIO::Job *job)
284
{
285
  TQDomDocument dom;
286
  TQDomElement knewstuff;
287
288
  kdDebug() << "got data: " << m_data[job] << endl;
289
290
  kapp->config()->setGroup("KNewStuffStatus");
291
292
  dom.setContent(m_data[job]);
293
  knewstuff = dom.documentElement();
294
295
  for(TQDomNode pn = knewstuff.firstChild(); !pn.isNull(); pn = pn.nextSibling())
296
  {
297
    TQDomElement stuff = pn.toElement();
298
299
    kdDebug() << "element: " << stuff.tagName() << endl;
300
301
    if(stuff.tagName() == "stuff")
302
    {
303
      Entry *entry = new Entry(stuff);
304
      kdDebug() << "TYPE::" << entry->type() << " FILTER::" << m_filter << endl;
305
      if(!entry->type().isEmpty())
306
      {
307
        if((!m_filter.isEmpty()) && (entry->type() != m_filter)) continue;
308
      }
309
310
      if((!m_filter.isEmpty()) && (m_jobs[job]))
311
      {
312
        Provider *p = m_jobs[job];
313
        addProvider(p);
314
        slotPage(m_frame);
315
        m_jobs[job] = 0;
316
      }
317
      addEntry(entry);
318
    }
319
  }
320
321
  m_data[job] = "";
322
}
323
324
int DownloadDialog::installStatus(Entry *entry)
325
{
326
  TQDate date;
327
  TQString datestring;
328
  int installed;
329
 
330
  kapp->config()->setGroup("KNewStuffStatus");
331
  datestring = kapp->config()->readEntry(entry->name());
332
  if(datestring.isNull()) installed = 0;
333
  else
334
  {
335
    date = TQDate::fromString(datestring, Qt::ISODate);
336
    if(!date.isValid()) installed = 0;
337
    else if(date < entry->releaseDate()) installed = -1;
338
    else installed = 1;
339
  }
340
341
  return installed;
342
}
343
344
void DownloadDialog::addEntry(Entry *entry)
345
{
346
  TQPixmap pix;
347
  int installed;
348
349
  /*if(m_engine)
350
  {
351
    if(m_map.count() == 0)
352
    {
353
      m_frame = addPage(i18n("Welcome"), i18n("Welcome"), TQPixmap(""));
354
      Provider *p = new Provider();
355
      p->setName(i18n("Generic"));
356
      addProvider(p);
357
      slotPage(m_frame);
358
    }
359
  }*/
360
  installed = installStatus(entry);
361
362
  if(installed > 0) pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small);
363
  else if(installed < 0) pix = TDEGlobal::iconLoader()->loadIcon("history", TDEIcon::Small);
364
  else pix = TQPixmap();
365
366
  TDEListViewItem *tmp_r = new TDEListViewItem(lv_r,
367
    entry->name(), entry->version(), TQString("%1").arg(entry->rating()));
368
  TDEListViewItem *tmp_d = new NumSortListViewItem(lv_d,
369
    entry->name(), entry->version(), TQString("%1").arg(entry->downloads()));
370
  TDEListViewItem *tmp_l = new TDEListViewItem(lv_l,
371
    entry->name(), entry->version(), TDEGlobal::locale()->formatDate(entry->releaseDate()));
372
373
  tmp_r->setPixmap(0, pix);
374
  tmp_d->setPixmap(0, pix);
375
  tmp_l->setPixmap(0, pix);
376
377
  m_entries.append(entry);
378
379
  kdDebug() << "added entry " << entry->name() << endl;
380
}
381
382
void DownloadDialog::slotData(TDEIO::Job *job, const TQByteArray &a)
383
{
384
  TQCString tmp(a, a.size() + 1);
385
  m_data[job].append(TQString::fromUtf8(tmp));
386
}
387
388
void DownloadDialog::slotDetails()
389
{
390
  Entry *e = getEntry();
391
  if(!e) return;
392
393
  TQString lang = TDEGlobal::locale()->language();
394
395
  TQString info = i18n
396
  (
397
    "Name: %1\n"
398
    "Author: %2\n"
399
    "License: %3\n"
400
    "Version: %4\n"
401
    "Release: %5\n"
402
    "Rating: %6\n"
403
    "Downloads: %7\n"
404
    "Release date: %8\n"
405
    "Summary: %9\n"
406
    ).arg(e->name()
407
    ).arg(e->author()
408
    ).arg(e->license()
409
    ).arg(e->version()
410
    ).arg(e->release()
411
    ).arg(e->rating()
412
    ).arg(e->downloads()
413
    ).arg(TDEGlobal::locale()->formatDate(e->releaseDate())
414
    ).arg(e->summary(lang)
415
  );
416
417
  info.append(i18n
418
  (
419
    "Preview: %1\n"
420
    "Payload: %2\n"
421
    ).arg(e->preview().url()
422
    ).arg(e->payload().url()
423
  ));
424
425
  KMessageBox::information(this, info, i18n("Details"));
426
}
427
428
void DownloadDialog::slotInstall()
429
{
430
  Entry *e = getEntry();
431
  if(!e) return;
432
433
  kdDebug() << "download entry now" << endl;
434
435
  if(m_engine)
436
  {
437
    m_engine->download(e);
438
    install(e);
439
  }
440
  else
441
  {
442
    m_s = new KNewStuffGeneric(e->type(), this);
443
444
    m_entry = e;
445
446
    KURL source = e->payload();
447
    KURL dest = KURL(m_s->downloadDestination(e));
448
449
    TDEIO::FileCopyJob *job = TDEIO::file_copy(source, dest, -1, true);
450
    connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotInstalled(TDEIO::Job*)));
451
  }
452
}
453
454
void DownloadDialog::install(Entry *e)
455
{
456
  kapp->config()->setGroup("KNewStuffStatus");
457
  kapp->config()->writeEntry(m_entryname, e->releaseDate().toString(Qt::ISODate));
458
  kapp->config()->sync();
459
460
  TQPixmap pix = TDEGlobal::iconLoader()->loadIcon("ok", TDEIcon::Small);
461
  m_entryitem = lv_r->findItem(m_entryname, 0);
462
  if(m_entryitem) m_entryitem->setPixmap(0, pix);
463
  m_entryitem = lv_d->findItem(m_entryname, 0);
464
  if(m_entryitem) m_entryitem->setPixmap(0, pix);
465
  m_entryitem = lv_l->findItem(m_entryname, 0);
466
  if(m_entryitem) m_entryitem->setPixmap(0, pix);
467
468
 
469
  TQPushButton *in;
470
  in = *(m_buttons[m_page]->at(0));
471
  if(in) in->setEnabled(false);
472
}
473
474
void DownloadDialog::slotInstalled(TDEIO::Job *job)
475
{
476
  bool ret = (job->error() == 0);
477
  TDEIO::FileCopyJob *cjob;
478
479
  if(ret)
480
  {
481
    cjob = static_cast<TDEIO::FileCopyJob*>(job);
482
    if(cjob)
483
    {
484
      ret = m_s->install(cjob->destURL().path());
485
    }
486
    else ret = false;
487
  }
488
489
  if(ret)
490
  {
491
    install(m_entry);
492
493
    KMessageBox::information(this, i18n("Installation successful."), i18n("Installation"));
494
  }
495
  else KMessageBox::error(this, i18n("Installation failed."), i18n("Installation"));
496
497
  delete m_s;
498
}
499
500
void DownloadDialog::slotTab(int tab)
501
{
502
  kdDebug() << "switch tab to: " << tab << endl;
503
  m_curtab = tab;
504
}
505
506
void DownloadDialog::slotSelected()
507
{
508
  TQString tmp;
509
  bool enabled;
510
  Entry *e = getEntry();
511
  TQString lang = TDEGlobal::locale()->language();
512
513
  if(e)
514
  {
515
    if(!e->preview(lang).isValid())
516
    {
517
      m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><i>%4</i><br>(%5)").arg(
518
        e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(e->summary(lang)).arg(e->license()));
519
    }
520
    else
521
    {
522
      TDEIO::NetAccess::download(e->preview(lang), tmp, this);
523
      m_rt->setText(TQString("<b>%1</b><br>%2<br>%3<br><br><img src='%4'><br><i>%5</i><br>(%6)").arg(
524
        e->name()).arg(e->author()).arg(TDEGlobal::locale()->formatDate(e->releaseDate())).arg(tmp).arg(e->summary(lang)).arg(e->license()));
525
    }
526
527
    if(installStatus(e) == 1) enabled = false;
528
    else enabled = true;
529
530
    TQPushButton *de, *in;
531
    in = *(m_buttons[m_page]->at(0));
532
    de = *(m_buttons[m_page]->at(1));
533
    if(in) in->setEnabled(enabled);
534
    if(de) de->setEnabled(true);
535
  }
536
}
537
538
Entry *DownloadDialog::getEntry()
539
{
540
  if(m_curtab == 0) m_entryitem = lv_r->currentItem();
541
  else if(m_curtab == 1) m_entryitem = lv_d->currentItem();
542
  else if(m_curtab == 2) m_entryitem = lv_l->currentItem();
543
  else return 0;
544
545
  m_entryname = m_entryitem->text(0);
546
547
  for(Entry *e = m_entries.first(); e; e = m_entries.next())
548
  {
549
    if(e->name() == m_entryname) return e;
550
  }
551
552
  return 0;
553
}
554
555
void DownloadDialog::slotPage(TQWidget *w)
556
{
557
  Provider *p;
558
559
  kdDebug() << "changed widget!!!" << endl;
560
561
  if(m_map.find(w) == m_map.end()) return;
562
563
  m_page = w;
564
565
  lv_r = *(m_map[w]->at(0));
566
  lv_d = *(m_map[w]->at(1));
567
  lv_l = *(m_map[w]->at(2));
568
  p = m_providers[w];
569
  m_rt = m_rts[w];
570
571
  kdDebug() << "valid change!!!; lv_r = " << lv_r << endl;
572
573
  if(m_engine) return;
574
575
  if(!m_filter.isEmpty()) return;
576
577
  lv_r->clear();
578
  lv_d->clear();
579
  lv_l->clear();
580
581
  kdDebug() << "-- fetch -- " << p->downloadUrl() << endl;
582
583
  loadProvider(p);
584
}
585
586
void DownloadDialog::loadProvider(Provider *p)
587
{
588
  TDEIO::TransferJob *job = TDEIO::get(p->downloadUrl());
589
590
  m_jobs[job] = p;
591
592
  connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
593
  connect(job, TQT_SIGNAL(data(TDEIO::Job*, const TQByteArray&)),
594
    TQT_SLOT(slotData(TDEIO::Job*, const TQByteArray&)));
595
}
596
597
void DownloadDialog::setType(TQString type)
598
{
599
  m_filter = type;
600
}
601
602
void DownloadDialog::setProviderList(const TQString& providerList)
603
{
604
  m_providerlist = providerList;
605
}
606
607
void DownloadDialog::slotOk()
608
{
609
}
610
611
void DownloadDialog::slotApply()
612
{
613
}
614
615
void DownloadDialog::open(const TQString& type, const TQString& caption)
616
{
617
  DownloadDialog d(0, caption);
618
  d.setType(type);
619
  d.load();
620
  d.exec();
621
}
622
623
void DownloadDialog::slotFinish()
624
{
625
  showPage(1);
626
  //updateBackground();
627
}
628
(-)tdewebdev/lib/compatibility/knewstuff/downloaddialog.h (-238 lines)
Lines 1-238 Link Here
1
/*
2
    This file is part of KNewStuff.
3
    Copyright (c) 2003 Josef Spillner <spillner@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_DOWNLOADDIALOG_H
21
#define KNEWSTUFF_DOWNLOADDIALOG_H
22
23
#include <kdialogbase.h>
24
#include <knewstuff/provider.h>
25
26
namespace TDEIO
27
{
28
  class Job;
29
}
30
31
class TDEListView;
32
class TQTextBrowser;
33
class TQFrame;
34
class KNewStuffGeneric;
35
36
namespace KNS
37
{
38
39
class ProviderLoader;
40
class Entry;
41
class Provider;
42
class Engine;
43
44
/**
45
 * @short Common download dialog for data browsing and installation.
46
 *
47
 * It provides an easy-to-use convenience method named open() which does all
48
 * the work, unless a more complex operation is needed.
49
 * \code
50
 * KNewStuff::DownloadDialog::open("kdesktop/wallpapers");
51
 * \endcode
52
 *
53
 * @author Josef Spillner (spillner@kde.org)
54
 * \par Maintainer:
55
 * Josef Spillner (spillner@kde.org)
56
 */
57
class KDE_EXPORT DownloadDialog : public KDialogBase
58
{
59
    Q_OBJECT
60
  
61
  public:
62
    /**
63
      Constructor.
64
65
      @param engine a pre-built engine object, or NULL if the download
66
                    dialog should create an engine on its own
67
      @param parent the parent window
68
      @param caption the dialog caption
69
    */
70
    DownloadDialog(Engine *engine, TQWidget *parent, const TQString& caption);
71
72
    /**
73
      Alternative constructor.
74
      Always uses an internal engine.
75
76
      @param parent the parent window
77
      @param caption the dialog caption
78
    */
79
    DownloadDialog(TQWidget *parent, const TQString& caption);
80
81
    /**
82
      Destructor.
83
    */
84
    ~DownloadDialog();
85
86
    /**
87
      Restricts the display of available data to a certain data type.
88
89
      @param type a Hotstuff data type such as "korganizer/calendar"
90
    */
91
    void setType(TQString type);
92
	// ### KDE 4.0: use const TQString&
93
94
    /**
95
      Fetches descriptions of all available data, optionally considering
96
      a previously set type.
97
    */
98
    void load();
99
100
    /**
101
      Explicitly uses this provider list instead of the one read from
102
      the application configuration.
103
104
      @param providerList the URL of the provider list
105
106
      @since 3.4
107
    */
108
    void setProviderList(const TQString& providerList);
109
110
    /**
111
      Fetches descriptions of all available data, optionally considering
112
      a previously set type.
113
114
      @param providerList the URl to the list of providers; if empty
115
             we first try the ProvidersUrl from TDEGlobal::config, then we
116
             fall back to a hardcoded value.
117
    */
118
    void load(TQString providerList); // KDE4: merge with load() above
119
120
    /**
121
      Adds another provider to the download dialog.
122
      This is normally done internally.
123
124
      @param p the Hotstuff provider to be added
125
    */
126
    void addProvider(Provider *p);
127
128
    /**
129
      Adds an additional entry to the current provider.
130
      This is normally done internally.
131
132
      @param entry a Hotstuff data entry to be added
133
    */
134
    void addEntry(Entry *entry);
135
136
    /**
137
      Clears the entry list of the current provider.
138
      This is normally done internally.
139
    */
140
    void clear();
141
142
    /**
143
      Opens the download dialog.
144
      This is a convenience method which automatically sets up the dialog.
145
      @see setType()
146
      @see load()
147
148
      @param type a data type such as "korganizer/calendar"
149
      @param caption the dialog caption
150
    */
151
    static void open(const TQString& type, const TQString& caption);
152
153
    /**
154
      Constructor.
155
156
      @param engine a pre-built engine object, or NULL if the download
157
                    dialog should create an engine on its own
158
      @param parent the parent window
159
    */
160
    DownloadDialog(Engine *engine, TQWidget *parent = 0);
161
    // ### KDE 4.0: remove and make caption/parent argument optional
162
163
    /**
164
      Alternative constructor.
165
      Always uses an internal engine.
166
167
      @param parent the parent window
168
    */
169
    DownloadDialog(TQWidget *parent = 0);
170
    // ### KDE 4.0: remove and make caption/parent argument optional
171
172
    /**
173
      Opens the download dialog.
174
      This is a convenience method which automatically sets up the dialog.
175
      @see setType()
176
      @see load()
177
178
      @param type a data type such as "korganizer/calendar"
179
    */
180
    static void open(TQString type);
181
    // ### KDE 4.0: remove and make caption/parent argument optional
182
183
  public slots:
184
    /**
185
      Availability of the provider list.
186
187
      @param list list of Hotstuff providers
188
    */
189
    void slotProviders(Provider::List *list);
190
191
  protected slots:
192
    void slotApply();
193
    void slotOk();
194
195
  private slots:
196
    void slotResult(TDEIO::Job *job);
197
    void slotData(TDEIO::Job *job, const TQByteArray &a);
198
    void slotInstall();
199
    void slotDetails();
200
    void slotInstalled(TDEIO::Job *job);
201
    void slotTab(int tab);
202
    void slotSelected();
203
    void slotPage(TQWidget *w);
204
    void slotFinish();
205
206
  private:
207
    void init(Engine *e);
208
    Entry *getEntry();
209
    void loadProvider(Provider *p);
210
    void install(Entry *e);
211
    int installStatus(Entry *e);
212
213
    ProviderLoader *m_loader;
214
    TQString m_entryname;
215
    TDEListView *lv_r, *lv_d, *lv_l;
216
    TQTextBrowser *m_rt;
217
    TQFrame *m_frame;
218
    TQListViewItem *m_entryitem;
219
    TQPtrList<Entry> m_entries;
220
    Entry *m_entry;
221
    KNewStuffGeneric *m_s;
222
    int m_curtab;
223
    TQMap<TQWidget*, TQValueList<TDEListView*>* > m_map;
224
    TQMap<TQWidget*, Provider*> m_providers;
225
    TQMap<TQWidget*, TQTextBrowser*> m_rts;
226
    TQMap<TQWidget*, TQValueList<TQPushButton*>* > m_buttons;
227
    TQMap<TDEIO::Job*, Provider*> m_jobs;
228
    TQMap<TDEIO::Job*, TQString> m_data;
229
    TQString m_filter;
230
    TQString m_providerlist;
231
    Engine *m_engine;
232
    TQWidget *m_page;
233
};
234
235
}
236
237
#endif
238
(-)tdewebdev/lib/compatibility/knewstuff/engine.cpp (-420 lines)
Lines 1-420 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include <tqcstring.h>
22
#include <tqdom.h>
23
#include <tqfileinfo.h>
24
25
#include <tdeapplication.h>
26
#include <kdebug.h>
27
#include <tdeio/job.h>
28
#include <tdelocale.h>
29
#include <tdemessagebox.h>
30
#include <kstandarddirs.h>
31
32
#include "knewstuff.h"
33
#include "downloaddialog.h"
34
#include "uploaddialog.h"
35
#include "providerdialog.h"
36
37
#include "engine.h"
38
#include "engine.moc"
39
40
using namespace KNS;
41
42
Engine::Engine( KNewStuff *newStuff, const TQString &type,
43
                TQWidget *parentWidget ) :
44
  mParentWidget( parentWidget ), mDownloadDialog( 0 ),
45
  mUploadDialog( 0 ), mProviderDialog( 0 ), mUploadProvider( 0 ),
46
  mNewStuff( newStuff ), mType( type )
47
{
48
  mProviderLoader = new ProviderLoader( mParentWidget );
49
50
  mNewStuffList.setAutoDelete( true );
51
}
52
53
Engine::Engine( KNewStuff *newStuff, const TQString &type,
54
                const TQString &providerList, TQWidget *parentWidget ) :
55
                mParentWidget( parentWidget ),
56
		mDownloadDialog( 0 ), mUploadDialog( 0 ),
57
		mProviderDialog( 0 ), mUploadProvider( 0 ),
58
                mProviderList( providerList ), mNewStuff( newStuff ),
59
		mType( type )
60
{
61
  mProviderLoader = new ProviderLoader( mParentWidget );
62
  mNewStuffList.setAutoDelete( true );
63
}
64
65
Engine::~Engine()
66
{
67
  delete mProviderLoader;
68
69
  delete mUploadDialog;
70
  delete mDownloadDialog;
71
}
72
73
void Engine::download()
74
{
75
  kdDebug(5850) << "Engine::download()" << endl;
76
77
  connect( mProviderLoader,
78
           TQT_SIGNAL( providersLoaded( Provider::List * ) ),
79
           TQT_SLOT( getMetaInformation( Provider::List * ) ) );
80
  mProviderLoader->load( mType, mProviderList );
81
}
82
83
void Engine::getMetaInformation( Provider::List *providers )
84
{
85
  mProviderLoader->disconnect();
86
87
  mNewStuffJobData.clear();
88
89
  if ( !mDownloadDialog ) {
90
    mDownloadDialog = new DownloadDialog( this, mParentWidget );
91
    mDownloadDialog->show();
92
  }
93
  mDownloadDialog->clear();
94
95
  Provider *p;
96
  for ( p = providers->first(); p; p = providers->next() ) {
97
    if ( p->downloadUrl().isEmpty() ) continue;
98
99
    TDEIO::TransferJob *job = TDEIO::get( p->downloadUrl() );
100
    connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
101
             TQT_SLOT( slotNewStuffJobResult( TDEIO::Job * ) ) );
102
    connect( job, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ),
103
             TQT_SLOT( slotNewStuffJobData( TDEIO::Job *, const TQByteArray & ) ) );
104
105
    mNewStuffJobData.insert( job, "" );
106
    mProviderJobs[ job ] = p;
107
  }
108
}
109
110
void Engine::slotNewStuffJobData( TDEIO::Job *job, const TQByteArray &data )
111
{
112
  if ( data.isEmpty() ) return;
113
114
  kdDebug(5850) << "Engine:slotNewStuffJobData()" << endl;
115
116
  TQCString str( data, data.size() + 1 );
117
118
  mNewStuffJobData[ job ].append( TQString::fromUtf8( str ) );
119
}
120
121
void Engine::slotNewStuffJobResult( TDEIO::Job *job )
122
{
123
  if ( job->error() ) {
124
    kdDebug(5850) << "Error downloading new stuff descriptions." << endl;
125
    job->showErrorDialog( mParentWidget );
126
  } else {
127
    TQString knewstuffDoc = mNewStuffJobData[ job ];
128
129
    kdDebug(5850) << "---START---" << endl << knewstuffDoc << "---END---" << endl;
130
131
    mDownloadDialog->addProvider( mProviderJobs[ job ] );
132
133
    TQDomDocument doc;
134
    if ( !doc.setContent( knewstuffDoc ) ) {
135
      kdDebug(5850) << "Error parsing knewstuff.xml." << endl;
136
      return;
137
    } else {
138
      TQDomElement knewstuff = doc.documentElement();
139
140
      if ( knewstuff.isNull() ) {
141
        kdDebug(5850) << "No document in knewstuffproviders.xml." << endl;
142
      } else {
143
        TQDomNode p;
144
        for ( p = knewstuff.firstChild(); !p.isNull(); p = p.nextSibling() ) {
145
          TQDomElement stuff = p.toElement();
146
          if ( stuff.tagName() != "stuff" ) continue;
147
          if ( stuff.attribute("type", mType) != mType ) continue;
148
149
          Entry *entry = new Entry( stuff );
150
          mNewStuffList.append( entry );
151
152
          mDownloadDialog->show();
153
154
          mDownloadDialog->addEntry( entry );
155
156
          kdDebug(5850) << "KNEWSTUFF: " << entry->name() << endl;
157
158
          kdDebug(5850) << "  SUMMARY: " << entry->summary() << endl;
159
          kdDebug(5850) << "  VERSION: " << entry->version() << endl;
160
          kdDebug(5850) << "  RELEASEDATE: " << entry->releaseDate().toString() << endl;
161
          kdDebug(5850) << "  RATING: " << entry->rating() << endl;
162
163
          kdDebug(5850) << "  LANGS: " << entry->langs().join(", ") << endl;
164
        }
165
      }
166
    }
167
  }
168
169
  mNewStuffJobData.remove( job );
170
  mProviderJobs.remove( job );
171
172
  if ( mNewStuffJobData.count() == 0 ) {
173
    mDownloadDialog->show();
174
    mDownloadDialog->raise();
175
  }
176
}
177
178
void Engine::download( Entry *entry )
179
{
180
  kdDebug(5850) << "Engine::download(entry)" << endl;
181
182
  KURL source = entry->payload();
183
  mDownloadDestination = mNewStuff->downloadDestination( entry );
184
185
  if ( mDownloadDestination.isEmpty() ) {
186
    kdDebug(5850) << "Empty downloadDestination. Cancelling download." << endl;
187
    return;
188
  }
189
190
  KURL destination = KURL( mDownloadDestination );
191
192
  kdDebug(5850) << "  SOURCE: " << source.url() << endl;
193
  kdDebug(5850) << "  DESTINATION: " << destination.url() << endl;
194
195
  TDEIO::FileCopyJob *job = TDEIO::file_copy( source, destination, -1, true );
196
  connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
197
           TQT_SLOT( slotDownloadJobResult( TDEIO::Job * ) ) );
198
}
199
200
void Engine::slotDownloadJobResult( TDEIO::Job *job )
201
{
202
  if ( job->error() ) {
203
    kdDebug(5850) << "Error downloading new stuff payload." << endl;
204
    job->showErrorDialog( mParentWidget );
205
    return;
206
  }
207
208
  if ( mNewStuff->install( mDownloadDestination ) ) {
209
    if ( !mIgnoreInstallResult ) {
210
      KMessageBox::information( mParentWidget,
211
                                i18n("Successfully installed hot new stuff.") );
212
    }
213
  } else 
214
    if ( !mIgnoreInstallResult ){
215
      KMessageBox::error( mParentWidget,
216
                          i18n("Failed to install hot new stuff.") );
217
  }
218
}
219
220
void Engine::upload(const TQString &fileName, const TQString &previewName )
221
{
222
  mUploadFile = fileName;
223
  mPreviewFile = previewName;
224
225
  connect( mProviderLoader,
226
           TQT_SIGNAL( providersLoaded( Provider::List * ) ),
227
           TQT_SLOT( selectUploadProvider( Provider::List * ) ) );
228
  mProviderLoader->load( mType );
229
}
230
231
void Engine::selectUploadProvider( Provider::List *providers )
232
{
233
  kdDebug(5850) << "Engine:selectUploadProvider()" << endl;
234
235
  mProviderLoader->disconnect();
236
237
  if ( !mProviderDialog ) {
238
    mProviderDialog = new ProviderDialog( this, mParentWidget );
239
  }
240
241
  mProviderDialog->clear();
242
243
  mProviderDialog->show();
244
  mProviderDialog->raise();
245
246
  for( Provider *p = providers->first(); p; p = providers->next() ) {
247
    mProviderDialog->addProvider( p );
248
  }
249
}
250
251
void Engine::requestMetaInformation( Provider *provider )
252
{
253
  mUploadProvider = provider;
254
255
  if ( !mUploadDialog ) {
256
    mUploadDialog = new UploadDialog( this, mParentWidget );
257
  }
258
  mUploadDialog->setPreviewFile( mPreviewFile );
259
  mUploadDialog->show();
260
  mUploadDialog->raise();
261
}
262
263
void Engine::upload( Entry *entry )
264
{
265
  if ( mUploadFile.isNull()) {
266
    mUploadFile = entry->fullName();
267
    mUploadFile = locateLocal( "data", TQString(kapp->instanceName()) + "/upload/" + mUploadFile );
268
269
    if ( !mNewStuff->createUploadFile( mUploadFile ) ) {
270
      KMessageBox::error( mParentWidget, i18n("Unable to create file to upload.") );
271
      emit uploadFinished( false );
272
      return;
273
    }
274
  }
275
276
  TQString lang = entry->langs().first();
277
  TQFileInfo fi( mUploadFile );
278
  entry->setPayload( KURL::fromPathOrURL( fi.fileName() ), lang );
279
280
  if ( !createMetaFile( entry ) ) {
281
    emit uploadFinished( false );
282
    return;
283
  } 
284
285
  TQString text = i18n("The files to be uploaded have been created at:\n");
286
  text.append( i18n("Data file: %1\n").arg( mUploadFile) );
287
  if (!mPreviewFile.isEmpty()) {
288
    text.append( i18n("Preview image: %1\n").arg( mPreviewFile) );
289
  }
290
  text.append( i18n("Content information: %1\n").arg( mUploadMetaFile) );
291
  text.append( i18n("Those files can now be uploaded.\n") );
292
  text.append( i18n("Beware that any people might have access to them at any time.") );
293
294
  TQString caption = i18n("Upload Files");
295
296
  if ( mUploadProvider->noUpload() ) {
297
    KURL noUploadUrl = mUploadProvider->noUploadUrl();
298
    if ( noUploadUrl.isEmpty() ) {
299
      text.append( i18n("Please upload the files manually.") );
300
      KMessageBox::information( mParentWidget, text, caption );
301
    } else {
302
      int result = KMessageBox::questionYesNo( mParentWidget, text, caption,
303
                                               i18n("Upload Info"),
304
                                               KStdGuiItem::close() );
305
      if ( result == KMessageBox::Yes ) {
306
        kapp->invokeBrowser( noUploadUrl.url() );
307
      }
308
    }
309
  } else {
310
    int result = KMessageBox::questionYesNo( mParentWidget, text, caption,
311
                                             i18n("&Upload"), KStdGuiItem::cancel() );
312
    if ( result == KMessageBox::Yes ) {
313
      KURL destination = mUploadProvider->uploadUrl();
314
      destination.setFileName( fi.fileName() );
315
316
      TDEIO::FileCopyJob *job = TDEIO::file_copy( KURL::fromPathOrURL( mUploadFile ), destination );
317
      connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
318
               TQT_SLOT( slotUploadPayloadJobResult( TDEIO::Job * ) ) );
319
    } else {
320
      emit uploadFinished( false );
321
    }
322
  }
323
}
324
325
bool Engine::createMetaFile( Entry *entry )
326
{
327
  TQDomDocument doc("knewstuff");
328
  doc.appendChild( doc.createProcessingInstruction(
329
                   "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
330
  TQDomElement de = doc.createElement("knewstuff");
331
  doc.appendChild( de );
332
333
  entry->setType(type());
334
  de.appendChild( entry->createDomElement( doc, de ) );
335
336
  kdDebug(5850) << "--DOM START--" << endl << doc.toString()
337
            << "--DOM_END--" << endl;
338
339
  if ( mUploadMetaFile.isNull() ) {
340
    mUploadMetaFile = entry->fullName() + ".meta";
341
    mUploadMetaFile = locateLocal( "data", TQString(kapp->instanceName()) + "/upload/" + mUploadMetaFile );
342
  }
343
344
  TQFile f( mUploadMetaFile );
345
  if ( !f.open( IO_WriteOnly ) ) {
346
    mUploadMetaFile = TQString();
347
    return false;
348
  }
349
350
  TQTextStream ts( &f );
351
  ts.setEncoding( TQTextStream::UnicodeUTF8 );
352
  ts << doc.toString();
353
354
  f.close();
355
356
  return true;
357
}
358
359
void Engine::slotUploadPayloadJobResult( TDEIO::Job *job )
360
{
361
  if ( job->error() ) {
362
    kdDebug(5850) << "Error uploading new stuff payload." << endl;
363
    job->showErrorDialog( mParentWidget );
364
    emit uploadFinished( false );
365
    return;
366
  }
367
368
  if (mPreviewFile.isEmpty()) {
369
    slotUploadPreviewJobResult(job);
370
    return;
371
  }
372
373
  TQFileInfo fi( mPreviewFile );
374
375
  KURL previewDestination = mUploadProvider->uploadUrl();
376
  previewDestination.setFileName( fi.fileName() );
377
378
  TDEIO::FileCopyJob *newJob = TDEIO::file_copy( KURL::fromPathOrURL( mPreviewFile ), previewDestination );
379
  connect( newJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
380
           TQT_SLOT( slotUploadPreviewJobResult( TDEIO::Job * ) ) );
381
}
382
383
void Engine::slotUploadPreviewJobResult( TDEIO::Job *job )
384
{
385
  if ( job->error() ) {
386
    kdDebug(5850) << "Error uploading new stuff preview." << endl;
387
    job->showErrorDialog( mParentWidget );
388
    emit uploadFinished( true );
389
    return;
390
  }
391
392
  TQFileInfo fi( mUploadMetaFile );
393
394
  KURL metaDestination = mUploadProvider->uploadUrl();
395
  metaDestination.setFileName( fi.fileName() );
396
397
  TDEIO::FileCopyJob *newJob = TDEIO::file_copy( KURL::fromPathOrURL( mUploadMetaFile ), metaDestination );
398
  connect( newJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
399
           TQT_SLOT( slotUploadMetaJobResult( TDEIO::Job * ) ) );
400
}
401
402
void Engine::slotUploadMetaJobResult( TDEIO::Job *job )
403
{
404
  mUploadMetaFile = TQString();
405
  if ( job->error() ) {
406
    kdDebug(5850) << "Error uploading new stuff metadata." << endl;
407
    job->showErrorDialog( mParentWidget );
408
    emit uploadFinished( false );
409
    return;
410
  }
411
412
  KMessageBox::information( mParentWidget,
413
                            i18n("Successfully uploaded new stuff.") );
414
  emit uploadFinished( true );
415
}
416
417
void Engine::ignoreInstallResult(bool ignore)
418
{
419
  mIgnoreInstallResult = ignore;
420
}
(-)tdewebdev/lib/compatibility/knewstuff/engine.h (-190 lines)
Lines 1-190 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_ENGINE_H
21
#define KNEWSTUFF_ENGINE_H
22
23
#include <tqmap.h>
24
#include <tqobject.h>
25
#include <tqstring.h>
26
27
#include "entry.h"
28
#include "provider.h"
29
30
namespace TDEIO { class Job; }
31
32
class KNewStuff;
33
34
namespace KNS {
35
36
class DownloadDialog;
37
class UploadDialog;
38
class ProviderDialog;
39
40
/**
41
 * @short Central class combining all possible KNewStuff operations.
42
 *
43
 * In most cases, Engine objects are built and used internally.
44
 * Using this class explicitely does however give fine-grained control about the
45
 * upload and download operations.
46
 *
47
 * @author Cornelius Schumacher (schumacher@kde.org)
48
 * \par Maintainer:
49
 * Josef Spillner (spillner@kde.org)
50
 */
51
class Engine : public TQObject
52
{
53
    Q_OBJECT
54
  
55
  public:
56
    /**
57
      Constructor.
58
59
      @param newStuff a KNewStuff object
60
      @param type the Hotstuff data type such as "korganizer/calendar"
61
      @param parentWidget the parent window
62
    */
63
    Engine( KNewStuff *newStuff, const TQString &type, TQWidget *parentWidget = 0 );
64
    /**
65
      Constructor.
66
67
      @param newStuff a KNewStuff object
68
      @param type the Hotstuff data type such as "korganizer/calendar"
69
      @param providerList the URL of the provider list
70
      @param parentWidget the parent window
71
    */
72
    Engine( KNewStuff *newStuff, const TQString &type, const TQString &providerList, TQWidget *parentWidget = 0 );
73
74
    /**
75
      Destructor.
76
    */
77
    virtual ~Engine();
78
79
    /**
80
      Returns the previously set data type.
81
82
      @return the Hotstuff data type
83
    */
84
    TQString type() const { return mType; }
85
86
    /**
87
      Returns the previously set parent widget.
88
89
      @return parent widget
90
    */
91
    TQWidget *parentWidget() const { return mParentWidget; }
92
93
    /**
94
      Initiates the download process, retrieving provider lists and invoking
95
      the download dialog.
96
    */
97
    void download();
98
99
    /**
100
      Initiates the upload process, invoking the provider selection dialog
101
      and the file upload dialog.
102
103
      @param fileName name of the payload data file
104
      @param previewName name of the preview image file
105
    */
106
    void upload( const TQString &fileName = TQString(), const TQString &previewName = TQString() );
107
108
    /**
109
      Downloads the specified data file.
110
111
      @param entry the Hotstuff data object to be downloaded
112
    */
113
    void download( Entry *entry );
114
115
    /**
116
      Asynchronous lookup of provider information such as upload and
117
      download locations, icon etc.
118
119
      @param provider the Hotstuff provider to request information from
120
    */
121
    void requestMetaInformation( Provider *provider );
122
123
    /**
124
      Uploads the specified data file to the provider-dependent location.
125
126
      @param entry the Hotstuff data object to be uploaded
127
    */
128
    void upload( Entry *entry );
129
    
130
    /**
131
    Ignores the return value of the install method. Used internally to
132
    avoid showing of the success/failure dialog when installation is done
133
    in another place, like in @ref KNewStuffSecure
134
     */
135
    void ignoreInstallResult(bool ignore);   
136
137
  signals:
138
    /** Emitted when the upload has finished.
139
      @param result indicates the success/failure of the upload
140
    */
141
    void uploadFinished( bool result );
142
  protected slots:
143
    void getMetaInformation( Provider::List *providers );
144
    void selectUploadProvider( Provider::List *providers );
145
146
    void slotNewStuffJobData( TDEIO::Job *job, const TQByteArray &data );
147
    void slotNewStuffJobResult( TDEIO::Job *job );
148
149
    void slotDownloadJobResult( TDEIO::Job *job );
150
151
    void slotUploadPayloadJobResult( TDEIO::Job *job );
152
    void slotUploadPreviewJobResult (TDEIO::Job *job );
153
    void slotUploadMetaJobResult( TDEIO::Job *job );
154
155
  protected:
156
    bool createMetaFile( Entry * );
157
    
158
  private:
159
    TQWidget *mParentWidget;
160
161
    ProviderLoader *mProviderLoader;
162
163
    TQMap<TDEIO::Job *,TQString> mNewStuffJobData;
164
    TQMap<TDEIO::Job *,Provider *> mProviderJobs;
165
166
    TQPtrList<Entry> mNewStuffList;
167
168
    DownloadDialog *mDownloadDialog;
169
    UploadDialog *mUploadDialog;
170
    ProviderDialog *mProviderDialog;
171
172
    TQString mDownloadDestination;
173
174
    Provider *mUploadProvider;
175
176
    TQString mUploadMetaFile;
177
    TQString mUploadFile;
178
    TQString mPreviewFile;
179
    TQString mProviderList;
180
181
    KNewStuff *mNewStuff;
182
183
    TQString mType;
184
    
185
    bool mIgnoreInstallResult;
186
};
187
188
}
189
190
#endif
(-)tdewebdev/lib/compatibility/knewstuff/entry.cpp (-294 lines)
Lines 1-294 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include "entry.h"
22
23
#include <tdeglobal.h>
24
#include <tdelocale.h>
25
26
using namespace KNS;
27
28
Entry::Entry() :
29
  mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
30
  mDownloads( 0 )
31
{
32
}
33
34
Entry::Entry( const TQDomElement &e )
35
{
36
  parseDomElement( e );
37
}
38
39
Entry::~Entry()
40
{
41
}
42
43
44
void Entry::setName( const TQString &name )
45
{
46
  mName = name;
47
}
48
49
TQString Entry::name() const
50
{
51
  return mName;
52
}
53
54
55
void Entry::setType( const TQString &type )
56
{
57
  mType = type;
58
}
59
60
TQString Entry::type() const
61
{
62
  return mType;
63
}
64
65
66
void Entry::setAuthor( const TQString &author )
67
{
68
  mAuthor = author;
69
}
70
71
TQString Entry::author() const
72
{
73
  return mAuthor;
74
}
75
76
77
void Entry::setLicence( const TQString &license )
78
{
79
  mLicence = license;
80
}
81
82
TQString Entry::license() const
83
{
84
  return mLicence;
85
}
86
87
88
void Entry::setSummary( const TQString &text, const TQString &lang )
89
{
90
  mSummaryMap.insert( lang, text );
91
92
  if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
93
}
94
95
TQString Entry::summary( const TQString &lang ) const
96
{
97
  if ( mSummaryMap.isEmpty() ) return TQString();
98
99
  if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
100
  else {
101
    TQStringList langs = TDEGlobal::locale()->languageList();
102
    for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
103
      if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
104
  }
105
  if ( !mSummaryMap[ TQString() ].isEmpty() ) return mSummaryMap[ TQString() ];
106
  else return *(mSummaryMap.begin());
107
}
108
109
110
void Entry::setVersion( const TQString &version )
111
{
112
  mVersion = version;
113
}
114
115
TQString Entry::version() const
116
{
117
  return mVersion;
118
}
119
120
121
void Entry::setRelease( int release )
122
{
123
  mRelease = release;
124
}
125
126
int Entry::release() const
127
{
128
  return mRelease;
129
}
130
131
132
void Entry::setReleaseDate( const TQDate &d )
133
{
134
  mReleaseDate = d;
135
}
136
137
TQDate Entry::releaseDate() const
138
{
139
  return mReleaseDate;
140
}
141
142
143
void Entry::setPayload( const KURL &url, const TQString &lang )
144
{
145
  mPayloadMap.insert( lang, url );
146
147
  if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
148
}
149
150
KURL Entry::payload( const TQString &lang ) const
151
{
152
  KURL payload = mPayloadMap[ lang ];
153
  if ( payload.isEmpty() ) {
154
    TQStringList langs = TDEGlobal::locale()->languageList();
155
    for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
156
      if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
157
  }
158
  if ( payload.isEmpty() ) payload = mPayloadMap [ TQString() ];
159
  if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
160
    payload = *(mPayloadMap.begin());
161
  }
162
  return payload;
163
}
164
165
166
void Entry::setPreview( const KURL &url, const TQString &lang )
167
{
168
  mPreviewMap.insert( lang, url );
169
  
170
  if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
171
}
172
173
KURL Entry::preview( const TQString &lang ) const
174
{
175
  KURL preview = mPreviewMap[ lang ];
176
  if ( preview.isEmpty() ) {
177
    TQStringList langs = TDEGlobal::locale()->languageList();
178
    for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
179
      if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
180
  }
181
  if ( preview.isEmpty() ) preview = mPreviewMap [ TQString() ];
182
  if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
183
    preview = *(mPreviewMap.begin());
184
  }
185
  return preview;
186
}
187
188
189
void Entry::setRating( int rating )
190
{
191
  mRating = rating;
192
}
193
194
int Entry::rating()
195
{
196
  return mRating;
197
}
198
199
200
void Entry::setDownloads( int downloads )
201
{
202
  mDownloads = downloads;
203
}
204
205
int Entry::downloads()
206
{
207
  return mDownloads;
208
}
209
210
TQString Entry::fullName()
211
{
212
  return name() + "-" + version() + "-" + TQString::number( release() );
213
}
214
215
TQStringList Entry::langs()
216
{
217
  return mLangs;
218
}
219
220
void Entry::parseDomElement( const TQDomElement &element )
221
{
222
  if ( element.tagName() != "stuff" ) return;
223
  mType = element.attribute("type");
224
225
  TQDomNode n;
226
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
227
    TQDomElement e = n.toElement();
228
    if ( e.tagName() == "name" ) setName( e.text().stripWhiteSpace() );
229
    if ( e.tagName() == "author" ) setAuthor( e.text().stripWhiteSpace() );
230
    if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
231
    if ( e.tagName() == "summary" ) {
232
      TQString lang = e.attribute( "lang" );
233
      setSummary( e.text().stripWhiteSpace(), lang );
234
    }
235
    if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
236
    if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
237
    if ( e.tagName() == "releasedate" ) {
238
      TQDate date = TQDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate );
239
      setReleaseDate( date );
240
    }
241
    if ( e.tagName() == "preview" ) {
242
      TQString lang = e.attribute( "lang" );
243
      setPreview( KURL( e.text().stripWhiteSpace() ), lang );
244
    }
245
    if ( e.tagName() == "payload" ) {
246
      TQString lang = e.attribute( "lang" );
247
      setPayload( KURL( e.text().stripWhiteSpace() ), lang );
248
    }
249
    if ( e.tagName() == "rating" ) setRating( e.text().toInt() );
250
    if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
251
  }
252
}
253
254
TQDomElement Entry::createDomElement( TQDomDocument &doc,
255
                                              TQDomElement &parent )
256
{
257
  TQDomElement entry = doc.createElement( "stuff" );
258
  entry.setAttribute("type", mType);
259
  parent.appendChild( entry );
260
261
  addElement( doc, entry, "name", name() );
262
  addElement( doc, entry, "author", author() );
263
  addElement( doc, entry, "licence", license() );
264
  addElement( doc, entry, "version", version() );
265
  addElement( doc, entry, "release", TQString::number( release() ) );
266
  addElement( doc, entry, "rating", TQString::number( rating() ) );
267
  addElement( doc, entry, "downloads", TQString::number( downloads() ) );
268
269
  addElement( doc, entry, "releasedate",
270
              releaseDate().toString( Qt::ISODate ) );
271
272
  TQStringList ls = langs();
273
  TQStringList::ConstIterator it;
274
  for( it = ls.begin(); it != ls.end(); ++it ) {
275
    TQDomElement e = addElement( doc, entry, "summary", summary( *it ) );
276
    e.setAttribute( "lang", *it );
277
    e = addElement( doc, entry, "preview", preview( *it ).url() );
278
    e.setAttribute( "lang", *it );
279
    e = addElement( doc, entry, "payload", payload( *it ).url() );
280
    e.setAttribute( "lang", *it );
281
  }
282
283
  return entry;
284
}
285
286
TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
287
                               const TQString &tag, const TQString &value )
288
{
289
  TQDomElement n = doc.createElement( tag );
290
  n.appendChild( doc.createTextNode( value ) );
291
  parent.appendChild( n );
292
293
  return n;
294
}
(-)tdewebdev/lib/compatibility/knewstuff/entry.h (-257 lines)
Lines 1-257 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_ENTRY_H
21
#define KNEWSTUFF_ENTRY_H
22
23
#include <tqdatetime.h>
24
#include <tqdom.h>
25
#include <tqmap.h>
26
#include <tqstring.h>
27
#include <tqstringlist.h>
28
29
#include <kurl.h>
30
31
namespace KNS {
32
33
/**
34
 * @short KNewStuff data entry container.
35
 *
36
 * This class provides accessor methods to the data objects
37
 * as used by KNewStuff.
38
 * It should probably not be used directly by the application.
39
 *
40
 * @author Cornelius Schumacher (schumacher@kde.org)
41
 * \par Maintainer:
42
 * Josef Spillner (spillner@kde.org)
43
 */
44
class KDE_EXPORT Entry
45
{
46
  public:
47
    Entry();
48
    /**
49
     * Constructor.
50
     */
51
    Entry( const TQDomElement & );
52
53
    /**
54
     * Destructor.
55
     */
56
    ~Entry();
57
58
    /**
59
     * Sets the (unique) name for this data object.
60
     */
61
    void setName( const TQString & );
62
63
    /**
64
     * Retrieve the name of the data object.
65
     *
66
     * @return object name
67
     */
68
    TQString name() const;
69
70
    /**
71
     * Sets the application type, e.g. 'kdesktop/wallpaper'.
72
     */
73
    void setType( const TQString & );
74
75
    /**
76
     * Retrieve the type of the data object.
77
     *
78
     * @return object type
79
     */
80
    TQString type() const;
81
82
    /**
83
     * Sets the full name of the object's author.
84
     */
85
    void setAuthor( const TQString & );
86
87
    /**
88
     * Retrieve the author's name of the object.
89
     *
90
     * @return object author
91
     */
92
    TQString author() const;
93
94
    /**
95
     * Sets the license (abbreviation) applicable to the object.
96
     */
97
    void setLicence( const TQString & );
98
99
    /**
100
     * Retrieve the license name of the object.
101
     *
102
     * @return object license
103
     */
104
    TQString license() const;
105
106
    /**
107
     * Sets a short description on what the object is all about.
108
     */
109
    void setSummary( const TQString &, const TQString &lang = TQString() );
110
111
    /**
112
     * Retrieve a short description about the object.
113
     *
114
     * @param lang preferred language, or TQString() for KDE default
115
     * @return object description
116
     */
117
    TQString summary( const TQString &lang = TQString() ) const;
118
119
    /**
120
     * Sets the version number.
121
     */
122
    void setVersion( const TQString & );
123
124
    /**
125
     * Retrieve the version string of the object.
126
     *
127
     * @return object version
128
     */
129
    TQString version() const;
130
131
    /**
132
     * Sets the release number, which is increased for feature-equal objects
133
     * with the same version number, but slightly updated contents.
134
     */
135
    void setRelease( int );
136
137
    /**
138
     * Retrieve the release number of the object
139
     *
140
     * @return object release
141
     */
142
    int release() const;
143
144
    /**
145
     * Sets the release date.
146
     */
147
    void setReleaseDate( const TQDate & );
148
149
    /**
150
     * Retrieve the date of the object's publication.
151
     *
152
     * @return object release date
153
     */
154
    TQDate releaseDate() const;
155
156
    /**
157
     * Sets the object's file.
158
     */
159
    void setPayload( const KURL &, const TQString &lang = TQString() );
160
161
    /**
162
     * Retrieve the file name of the object.
163
     *
164
     * @param lang preferred language, or TQString() for KDE default
165
     * @return object filename
166
     */
167
    KURL payload( const TQString &lang = TQString() ) const;
168
169
    /**
170
     * Sets the object's preview file, if available. This should be a
171
     * picture file.
172
     */
173
    void setPreview( const KURL &, const TQString &lang = TQString() );
174
175
    /**
176
     * Retrieve the file name of an image containing a preview of the object.
177
     *
178
     * @param lang preferred language, or TQString() for KDE default
179
     * @return object preview filename
180
     */
181
    KURL preview( const TQString &lang = TQString() ) const;
182
183
    /**
184
     * Sets the rating between 0 (worst) and 10 (best).
185
     *
186
     * @internal
187
     */
188
    void setRating( int );
189
190
    /**
191
     * Retrieve the rating for the object, which has been determined by its
192
     * users and thus might change over time.
193
     *
194
     * @return object rating
195
     */
196
    int rating();
197
198
    /**
199
     * Sets the number of downloads.
200
     * 
201
     * @internal
202
     */
203
    void setDownloads( int );
204
205
    /**
206
     * Retrieve the download count for the object, which has been determined
207
     * by its hosting sites and thus might change over time.
208
     *
209
     * @return object download count
210
     */
211
    int downloads();
212
213
    /**
214
     * Return the full name for the meta information. It is constructed as
215
     * name-version-release.
216
     */
217
    TQString fullName();
218
219
    /**
220
     * Return the list of languages this object supports.
221
     */
222
    TQStringList langs();
223
224
    /**
225
     * @internal
226
     */
227
    void parseDomElement( const TQDomElement & );
228
229
    /**
230
     * @internal
231
     */
232
    TQDomElement createDomElement( TQDomDocument &, TQDomElement &parent );
233
234
  protected:
235
    TQDomElement addElement( TQDomDocument &doc, TQDomElement &parent,
236
                            const TQString &tag, const TQString &value );
237
238
  private:
239
    TQString mName;
240
    TQString mType;
241
    TQString mAuthor;
242
    TQString mLicence;
243
    TQMap<TQString,TQString> mSummaryMap;
244
    TQString mVersion;
245
    int mRelease;
246
    TQDate mReleaseDate;
247
    TQMap<TQString,KURL> mPayloadMap;
248
    TQMap<TQString,KURL> mPreviewMap;
249
    int mRating;
250
    int mDownloads;
251
252
    TQStringList mLangs;
253
};
254
255
}
256
257
#endif
(-)tdewebdev/lib/compatibility/knewstuff/knewstuff.cpp (-86 lines)
Lines 1-86 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include <tdeaction.h>
22
#include <tdeapplication.h>
23
#include <kdebug.h>
24
#include <tdelocale.h>
25
#include <kstandarddirs.h>
26
27
#include "engine.h"
28
29
#include "knewstuff.h"
30
31
using namespace KNS;
32
33
TDEAction* KNS::standardAction(const TQString& what,
34
                             const TQObject *recvr,
35
                             const char *slot, TDEActionCollection* parent,
36
                             const char *name)
37
{
38
    return new TDEAction(i18n("Download New %1").arg(what), "knewstuff",
39
                       0, recvr, slot, parent, name);
40
}
41
42
KNewStuff::KNewStuff( const TQString &type, TQWidget *parentWidget )
43
{
44
    mEngine = new Engine( this, type, parentWidget );
45
}
46
47
KNewStuff::KNewStuff( const TQString &type, const TQString &providerList, TQWidget *parentWidget )
48
{
49
  mEngine = new Engine( this, type, providerList, parentWidget );
50
}
51
52
TQString KNewStuff::type() const
53
{
54
  return mEngine->type();
55
}
56
57
TQWidget *KNewStuff::parentWidget() const
58
{
59
  return mEngine->parentWidget();
60
}
61
62
KNewStuff::~KNewStuff()
63
{
64
  delete mEngine;
65
}
66
67
void KNewStuff::download()
68
{
69
  mEngine->download();
70
}
71
72
TQString KNewStuff::downloadDestination( Entry * )
73
{
74
  return TDEGlobal::dirs()->saveLocation( "tmp" ) +
75
         TDEApplication::randomString( 10 );
76
}
77
78
void KNewStuff::upload()
79
{
80
  mEngine->upload();
81
}
82
83
void KNewStuff::upload( const TQString &fileName, const TQString previewName )
84
{
85
  mEngine->upload(fileName, previewName);
86
}
(-)tdewebdev/lib/compatibility/knewstuff/knewstuff.h (-161 lines)
Lines 1-161 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_H
21
#define KNEWSTUFF_H
22
23
#include <tqstring.h>
24
25
#include <kdemacros.h>
26
27
class TQObject;
28
class TQWidget;
29
class TDEAction;
30
class TDEActionCollection;
31
32
namespace KNS {
33
class Engine;
34
class Entry;
35
36
TDEAction* standardAction(const TQString& what,
37
                        const TQObject *recvr,
38
                        const char *slot,
39
                        TDEActionCollection* parent,
40
                        const char *name = 0);
41
}
42
43
/**
44
 * @short This class provides the functionality to download and upload "new stuff".
45
 *
46
 * Applications have to subclass KNewStuff, implement the pure virtual functions
47
 * and link to against libknewstuff.
48
 *
49
 * By calling download() the download process is started which means that a list
50
 * of "providers" is fetched from a "master server", information about new stuff
51
 * is collected from the providers and presented to the user. Selected entries
52
 * get downloaded and installed to the application. The required functions to
53
 * install new stuff are provided by implementing install(). The location where
54
 * the downloaded files are stored can be customized by reimplementing
55
 * downloadDestination().
56
 *
57
 * By calling upload() the upload process is started which means the user has to
58
 * select a provider from the list fetched from the master server and to put in
59
 * information about the entry to be uploaded. Then the file to be uploaded is
60
 * fetched from the application by calling createUploadFile() and transfered to
61
 * the upload destination specified in the provider list.
62
 *
63
 * @author Cornelius Schumacher (schumacher@kde.org)
64
 * \par Maintainer:
65
 * Josef Spillner (spillner@kde.org)
66
 *
67
 * @since 3.3
68
 */
69
class KDE_EXPORT KNewStuff
70
{
71
  public:
72
    /**
73
      Constructor.
74
75
      @param type type of data to be handled, should be something like
76
                  korganizer/calendar, kword/template, kdesktop/wallpaper
77
      @param parentWidget parent widget of dialogs opened by the KNewStuff
78
                          engine
79
    */
80
    KNewStuff( const TQString &type, TQWidget *parentWidget = 0 );
81
    
82
    /**
83
      Constructor.
84
85
      @param type type of data to be handled, should be something like
86
                  korganizer/calendar, kword/template, kdesktop/wallpaper
87
      @param providerList the URL of the provider list
88
      @param parentWidget parent widget of dialogs opened by the KNewStuff
89
                          engine
90
    */
91
    KNewStuff( const TQString &type, const TQString &providerList, TQWidget *parentWidget = 0 );
92
    virtual ~KNewStuff();
93
94
    /**
95
      Return type of data.
96
    */
97
    TQString type() const;
98
99
    /**
100
      Return parent widget.
101
    */
102
    TQWidget *parentWidget() const;
103
104
    /**
105
      Start download process.
106
    */
107
    void download();
108
109
    /**
110
      Start upload process.
111
    */
112
    void upload();
113
114
    /**
115
      Upload with pre-defined files.
116
    */
117
    void upload( const TQString &fileName, const TQString previewName );
118
119
    /**
120
      Install file to application. The given fileName points to the file
121
      downloaded by the KNewStuff engine. This is a temporary file by default.
122
      The application can do whatever is needed to handle the information
123
      contained in the file.
124
125
      The function returns true, when the installation
126
      was successful and false if were errors.
127
128
      @param fileName name of downloaded file
129
    */
130
    virtual bool install( const TQString &fileName ) = 0;
131
    /**
132
      Create a file to be uploaded to a "new stuff provider" and return the
133
      filename. The format of the file is application specific. The only
134
      constraint is that the corresponding install() implementation is able to
135
      use the file.
136
137
      @param fileName name of the file to be written
138
      @return @c true on success, @c false on error.
139
    */
140
    virtual bool createUploadFile( const TQString &fileName ) = 0;
141
142
    /**
143
      Return a filename which should be used as destination for downloading the
144
      specified new stuff entry. Reimplement this function, if you don't want
145
      the new stuff to be downloaded to a temporary file.
146
    */
147
    virtual TQString downloadDestination( KNS::Entry *entry );
148
    
149
    
150
  protected:
151
    /**
152
      Get the pointer to the engine. Needed by subclasses to access the KNS::Engine object.
153
     */  
154
    KNS::Engine *engine() { return mEngine; }  
155
156
    
157
  private:
158
    KNS::Engine *mEngine;
159
};
160
161
#endif
(-)tdewebdev/lib/compatibility/knewstuff/knewstuffgeneric.cpp (-140 lines)
Lines 1-140 Link Here
1
/*
2
    This file is part of KDE.
3
4
    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
6
    This library is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU Library General Public
8
    License as published by the Free Software Foundation; either
9
    version 2 of the License, or (at your option) any later version.
10
11
    This library is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
    Library General Public License for more details.
15
16
    You should have received a copy of the GNU Library General Public License
17
    along with this library; see the file COPYING.LIB.  If not, write to
18
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
    Boston, MA 02110-1301, USA.
20
*/
21
22
#include <tqfile.h>
23
#include <tqtextstream.h>
24
#include <tqdir.h>
25
26
#include <kdebug.h>
27
#include <tdelocale.h>
28
#include <kprocess.h>
29
#include <tdeconfig.h>
30
#include <kstandarddirs.h>
31
#include <tdemessagebox.h>
32
#include <ktar.h>
33
34
#include "entry.h"
35
36
#include "knewstuffgeneric.h"
37
38
using namespace std;
39
40
KNewStuffGeneric::KNewStuffGeneric( const TQString &type, TQWidget *parent )
41
  : KNewStuff( type, parent )
42
{
43
  mConfig = TDEGlobal::config();
44
}
45
46
KNewStuffGeneric::~KNewStuffGeneric()
47
{
48
}
49
50
bool KNewStuffGeneric::install( const TQString &fileName )
51
{
52
  kdDebug(5850) << "KNewStuffGeneric::install(): " << fileName << endl;
53
  TQStringList list, list2;
54
55
  mConfig->setGroup("KNewStuff");
56
57
  TQString uncompress = mConfig->readEntry( "Uncompress" );
58
  if ( !uncompress.isEmpty() ) {
59
    kdDebug(5850) << "Uncompression method: " << uncompress << endl;
60
    KTar tar(fileName, uncompress);
61
    tar.open(IO_ReadOnly);
62
    const KArchiveDirectory *dir = tar.directory();
63
    dir->copyTo(destinationPath(0));
64
    tar.close();
65
    TQFile::remove(fileName);
66
  }
67
68
  TQString cmd = mConfig->readEntry( "InstallationCommand" );
69
  if ( !cmd.isEmpty() ) {
70
    kdDebug(5850) << "InstallationCommand: " << cmd << endl;
71
    list = TQStringList::split( " ", cmd );
72
    for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it) {
73
        list2 << (*it).replace("%f", fileName);
74
    }
75
    TDEProcess proc;
76
    proc << list2;
77
    proc.start( TDEProcess::Block );
78
  }
79
80
  return true;
81
}
82
83
bool KNewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
84
{
85
  return false;
86
}
87
88
TQString KNewStuffGeneric::destinationPath( KNS::Entry *entry )
89
{
90
  TQString path, file, target;
91
92
  mConfig->setGroup("KNewStuff");
93
94
  if( entry ) target = entry->fullName();
95
  else target = "/";
96
  TQString res = mConfig->readEntry( "StandardResource" );
97
  if ( res.isEmpty() )
98
  {
99
    target = mConfig->readEntry("TargetDir");
100
    if ( !target.isEmpty())
101
    {
102
      res = "data";
103
      if ( entry ) target.append("/" + entry->fullName());
104
      else target.append("/");
105
    }
106
  }
107
  if ( res.isEmpty() )
108
  {
109
    path = mConfig->readEntry( "InstallPath" );
110
  }
111
  if ( res.isEmpty() && path.isEmpty() )
112
  {
113
    if ( !entry ) return TQString();
114
    else return KNewStuff::downloadDestination( entry );
115
  }
116
117
  if ( !path.isEmpty() )
118
  {
119
    file = TQDir::home().path() + "/" + path + "/";
120
    if ( entry ) file += entry->fullName();
121
  }
122
  else file = locateLocal( res.utf8() , target );
123
124
  return file;
125
}
126
127
TQString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
128
{
129
  TQString file = destinationPath(entry);
130
131
  if ( TDEStandardDirs::exists( file ) ) {
132
    int result = KMessageBox::warningContinueCancel( parentWidget(),
133
        i18n("The file '%1' already exists. Do you want to override it?")
134
        .arg( file ),
135
        TQString(), i18n("Overwrite") );
136
    if ( result == KMessageBox::Cancel ) return TQString();
137
  }
138
139
  return file;
140
}
(-)tdewebdev/lib/compatibility/knewstuff/knewstuffgeneric.h (-86 lines)
Lines 1-86 Link Here
1
/*
2
    This file is part of KDE.
3
4
    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
6
    This library is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU Library General Public
8
    License as published by the Free Software Foundation; either
9
    version 2 of the License, or (at your option) any later version.
10
11
    This library is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
    Library General Public License for more details.
15
16
    You should have received a copy of the GNU Library General Public License
17
    along with this library; see the file COPYING.LIB.  If not, write to
18
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
    Boston, MA 02110-1301, USA.
20
*/
21
#ifndef KNEWSTUFFGENERIC_H
22
#define KNEWSTUFFGENERIC_H
23
24
#include "knewstuff.h"
25
26
class TDEConfig;
27
28
/**
29
 * @short Basic KNewStuff class with predefined actions.
30
 *
31
 * This class is used for data uploads and installation.
32
 * \code
33
 * TQString payload, preview;
34
 * KNewStuffGeneric *ns = new KNewStuffGeneric("kamikaze/level", this);
35
 * ns->upload(payload, preview);
36
 * \endcode
37
 *
38
 * @author Cornelius Schumacher (schumacher@kde.org)
39
 * \par Maintainer:
40
 * Josef Spillner (spillner@kde.org)
41
 */
42
class KDE_EXPORT KNewStuffGeneric : public KNewStuff
43
{
44
  public:
45
    /**
46
      Constructor.
47
48
      @param type a Hotstuff data type such as "korganizer/calendar"
49
      @param parent the parent window.
50
    */
51
    KNewStuffGeneric( const TQString &type, TQWidget *parent = 0 );
52
    ~KNewStuffGeneric();
53
54
    /**
55
      Installs a downloaded file according to the application's configuration.
56
57
      @param fileName filename of the donwloaded file
58
      @return @c true in case of installation success, @c false otherwise
59
    */
60
    bool install( const TQString &fileName );
61
62
    /**
63
      Creates a file suitable for upload.
64
      Note that this method always fails, since using KNewStuffGeneric
65
      means that the provided file must already be in a usable format.
66
67
      @param fileName the name of the file to upload after its creation
68
      @return @c true in case of creation success, @c false otherwise
69
    */
70
    bool createUploadFile( const TQString &fileName );
71
72
    /**
73
      Queries the preferred destination file for a download.
74
75
      @param entry a Hotstuff data entry
76
      @return destination filename, or 0 to return directory only
77
    */
78
    TQString downloadDestination( KNS::Entry *entry );
79
80
  private:
81
    TQString destinationPath( KNS::Entry *entry );
82
83
    TDEConfig *mConfig;
84
};
85
86
#endif
(-)tdewebdev/lib/compatibility/knewstuff/knewstuffsecure.cpp (-240 lines)
Lines 1-240 Link Here
1
/***************************************************************************
2
                          knewstuffsecure.cpp  -  description
3
                             -------------------
4
    begin                : Tue Jun 22 12:19:55 2004
5
    copyright          : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
6
 ***************************************************************************/
7
8
/***************************************************************************
9
 *                                                                         *
10
 *   This program is free software; you can redistribute it and/or modify  *
11
 *   it under the terms of the GNU Library General Public License as       *
12
 *   published by the Free Software Foundation; version 2 of the License.  *
13
 *                                                                         *
14
 ***************************************************************************/
15
//qt includes
16
#include <tqfileinfo.h>
17
18
//kde includes
19
#include <tdeconfig.h>
20
#include <kdebug.h>
21
#include <tdeglobal.h>
22
#include <tdeio/netaccess.h>
23
#include <tdelocale.h>
24
#include <tdemessagebox.h>
25
#include <kstandarddirs.h>
26
#include <ktar.h>
27
#include <ktempdir.h>
28
29
//app includes
30
#include "engine.h"
31
#include "knewstuffsecure.h"
32
#include "security.h"
33
34
using namespace KNS;
35
36
KNewStuffSecure::KNewStuffSecure(const TQString &type,  TQWidget *parentWidget)
37
 : KNewStuff(type, parentWidget)
38
{
39
  m_tempDir = 0L;
40
  connect(engine(), TQT_SIGNAL(uploadFinished(bool)), TQT_SLOT(slotUploadFinished(bool)));
41
}
42
43
44
KNewStuffSecure::~KNewStuffSecure()
45
{
46
  removeTempDirectory();
47
}
48
49
bool KNewStuffSecure::install(const TQString &fileName)
50
{
51
  bool ok = true;
52
53
  removeTempDirectory();
54
  m_tempDir = new KTempDir();
55
  m_tempDir->setAutoDelete(true);
56
  KTar tar(fileName, "application/x-gzip");
57
  if (tar.open(IO_ReadOnly))
58
  {
59
      const KArchiveDirectory *directory = tar.directory();
60
      directory->copyTo(m_tempDir->name(), true);
61
      m_tarName = "";
62
      TQStringList entries = directory->entries();
63
      for (TQStringList::Iterator it = entries.begin(); it != entries.end(); ++it)
64
      {
65
        if (*it != "signature" && *it != "md5sum")
66
        {
67
          m_tarName = *it;
68
          break;
69
        }
70
      }
71
      tar.close();
72
      if (m_tarName.isEmpty())
73
        ok = false;
74
      else
75
      {
76
         m_tarName.prepend(m_tempDir->name());
77
         connect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
78
         Security::ref()->checkValidity(m_tarName);
79
      }
80
  } else
81
      ok = false;
82
  if (!ok)
83
    KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded resource tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Resource Installation Error"));
84
  return ok;
85
}
86
87
void KNewStuffSecure::slotValidated(int result)
88
{
89
   TQString errorString;
90
   TQString signatureStr;
91
   bool valid = true;
92
   if (result == -1)
93
   {
94
     errorString ="<br>-    " +  i18n("No keys were found.");
95
     valid = false;
96
   } else
97
   if (result == 0)
98
   {
99
       errorString ="<br>-    " +  i18n("The validation failed for unknown reason.");
100
       valid = false;
101
   } else
102
   {
103
      KeyStruct key = Security::ref()->signatureKey();
104
      if (!(result & Security::MD5_OK ))
105
      {
106
          errorString = "<br>-    " + i18n("The MD5SUM check failed, the archive might be broken.");
107
          valid = false;
108
      }
109
      if (result & Security::SIGNED_BAD)
110
      {
111
          errorString += "<br>-    " + i18n("The signature is bad, the archive might be broken or altered.");
112
          valid = false;
113
      }
114
      if (result & Security::SIGNED_OK)
115
      {
116
         if (result & Security::TRUSTED)
117
         {
118
            kdDebug() << "Signed and trusted " << endl;
119
         } else
120
         {
121
            errorString += "<br>-    " + i18n("The signature is valid, but untrusted.");
122
            valid = false;
123
         }
124
      }
125
      if (result & Security::UNKNOWN)
126
      {
127
          errorString += "<br>-    " + i18n("The signature is unknown.");
128
          valid = false;
129
      } else
130
      {
131
          signatureStr = i18n("The resource was signed with key <i>0x%1</i>, belonging to <i>%2 &lt;%3&gt;</i>.").arg(key.id.right(8)).arg(key.name).arg(key.mail);
132
      }
133
   }
134
  if (!valid)
135
  {
136
      signatureStr.prepend( "<br>");
137
      if (KMessageBox::warningContinueCancel(parentWidget(), i18n("<qt>There is a problem with the resource file you have downloaded. The errors are :<b>%1</b><br>%2<br><br>Installation of the resource is <b>not recommended</b>.<br><br>Do you want to proceed with the installation?</qt>").arg(errorString).arg(signatureStr), i18n("Problematic Resource File")) == KMessageBox::Continue)
138
          valid = true;
139
  } else
140
    KMessageBox::information(parentWidget(), i18n("<qt>%1<br><br>Press OK to install it.</qt>").arg(signatureStr), i18n("Valid Resource"), "Show Valid Signature Information");
141
  if (valid)
142
  {
143
     installResource();
144
     emit installFinished();
145
  } else
146
  {
147
    TDEConfig *cfg = TDEGlobal::config();
148
    cfg->deleteGroup("KNewStuffStatus");
149
    cfg->setGroup("KNewStuffStatus");
150
    for (TQMap<TQString, TQString>::ConstIterator it = m_installedResources.constBegin(); it != m_installedResources.constEnd(); ++it)
151
    {
152
      cfg->writeEntry(it.key(), it.data());
153
    }
154
    cfg->sync();
155
  }
156
  removeTempDirectory();
157
  disconnect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
158
}
159
160
void KNewStuffSecure::downloadResource()
161
{
162
  TDEConfig *cfg = TDEGlobal::config();
163
  m_installedResources = cfg->entryMap("KNewStuffStatus");
164
  engine()->ignoreInstallResult(true);
165
  KNewStuff::download();
166
}
167
168
bool KNewStuffSecure::createUploadFile(const TQString &fileName)
169
{
170
  Q_UNUSED(fileName);
171
  return true; 
172
}
173
174
void KNewStuffSecure::uploadResource(const TQString& fileName)
175
{
176
  connect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
177
  removeTempDirectory();
178
  m_tempDir = new KTempDir();
179
  m_tempDir->setAutoDelete(true);
180
  TQFileInfo f(fileName);
181
  m_signedFileName = m_tempDir->name() + "/" + f.fileName();
182
  TDEIO::NetAccess::file_copy(KURL::fromPathOrURL(fileName), KURL::fromPathOrURL(m_signedFileName), -1, true);
183
  Security::ref()->signFile(m_signedFileName);
184
}
185
186
void KNewStuffSecure::slotFileSigned(int result)
187
{
188
  if (result == 0)
189
  {
190
    KMessageBox::error(parentWidget(), i18n("The signing failed for unknown reason."));    
191
  } else
192
  {
193
    if (result & Security::BAD_PASSPHRASE)
194
    {
195
      if (KMessageBox::warningContinueCancel(parentWidget(), i18n("There are no keys usable for signing or you did not entered the correct passphrase.\nProceed without signing the resource?")) == KMessageBox::Cancel)
196
      {
197
        disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
198
        removeTempDirectory();
199
        return;    
200
      }
201
    } 
202
    KTar tar(m_signedFileName + ".signed", "application/x-gzip");
203
    tar.open(IO_WriteOnly);
204
    TQStringList files;
205
    files << m_signedFileName;
206
    files << m_tempDir->name() + "/md5sum";
207
    files << m_tempDir->name() + "/signature";
208
  
209
    for (TQStringList::Iterator it_f = files.begin(); it_f != files.end(); ++it_f)
210
    {
211
      TQFile file(*it_f);
212
      file.open(IO_ReadOnly);
213
      TQByteArray bArray = file.readAll();
214
      tar.writeFile(TQFileInfo(file).fileName(), "user", "group", bArray.size(), bArray.data());
215
      file.close();
216
    }
217
    tar.close();
218
    TDEIO::NetAccess::file_move(KURL::fromPathOrURL(m_signedFileName + ".signed"), KURL::fromPathOrURL(m_signedFileName), -1, true);
219
    KNewStuff::upload(m_signedFileName, TQString());
220
    disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
221
  }
222
}
223
224
void KNewStuffSecure::slotUploadFinished(bool result)
225
{
226
  Q_UNUSED(result);
227
  removeTempDirectory();
228
}
229
230
void KNewStuffSecure::removeTempDirectory()
231
{
232
  if (m_tempDir)
233
  {
234
    TDEIO::NetAccess::del(KURL().fromPathOrURL(m_tempDir->name()), parentWidget());
235
    delete m_tempDir;
236
    m_tempDir = 0L;
237
  }
238
}
239
240
#include "knewstuffsecure.moc"
(-)tdewebdev/lib/compatibility/knewstuff/knewstuffsecure.h (-102 lines)
Lines 1-102 Link Here
1
/***************************************************************************
2
                        knewstuffsecure.h  -  description
3
                             -------------------
4
    begin               : Tue Jun 22 12:19:55 2004
5
    copyright          : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
6
 ***************************************************************************/
7
8
/***************************************************************************
9
 *                                                                         *
10
 *   This program is free software; you can redistribute it and/or modify  *
11
 *   it under the terms of the GNU Library General Public License as       *
12
 *   published by the Free Software Foundation; version 2 of the License.  *
13
 *                                                                         *
14
 ***************************************************************************/
15
16
#ifndef KNEWSTUFFSECURE_H
17
#define KNEWSTUFFSECURE_H
18
19
//qt includes
20
#include <tqobject.h>
21
22
//kde includes
23
#include "knewstuff.h"
24
25
class KTempDir;
26
/**
27
Makes possible downloading and installing signed resource files from a server.
28
You must subclass it and implement the @ref installResource() pure
29
virtual method to install a resource. For uploading you must create a resource
30
tarball (which is installabale by @ref installResource()) and call the 
31
@ref uploadResource() method with this tarball as the argument.
32
Signing and verification is done by the gpg application, so the user must
33
have it installed, otherwise this class does not give any extra security compared
34
to the standard KNewStuff class.
35
36
@since 3.4
37
38
@author Andras Mantia <amantia@kde.org>
39
*/
40
class KDE_EXPORT KNewStuffSecure : public  TQObject, public KNewStuff
41
{
42
  Q_OBJECT
43
  
44
45
public:
46
    /** Constructor.
47
48
      @param type type of data to be handled, should be something like
49
             korganizer/calendar, kword/template, kdesktop/wallpaper
50
      @param parentWidget parent widget of dialogs opened by the KNewStuff
51
              engine
52
     */
53
    KNewStuffSecure(const TQString &type,  TQWidget *parentWidget=0);
54
    virtual ~KNewStuffSecure();
55
56
    /** Installs the downloaded resource. Do not call or reimplement directly. 
57
        It's reimplemented from KNewStuff for internal reasons. 
58
    */
59
    bool install( const TQString &fileName );
60
    
61
    /** Reimplemented for internal reasons. */
62
    bool createUploadFile(const TQString &fileName);
63
    
64
    /** Initiates a download. This is the method that must be called in
65
    * order to download a signed resource. */
66
    void downloadResource();
67
    
68
    /** Signs the file and uploads to the central server.
69
    * @param fileName The file to be signed and uploaded
70
    */
71
    void uploadResource(const TQString &fileName);
72
    
73
74
private slots:
75
    /** Checks the validity of the downloaded tarball and installs it*/
76
    void slotValidated(int result);
77
    /** The file is signed, so it can be uploaded.*/
78
    void slotFileSigned(int result);
79
    /** Called when the upload has finished. 
80
        @param result the result of the upload
81
        Be careful if you reimplement it, as it deletes the temporary directory
82
        m_tempDir used for upload. You must also delete it (call the parent's method)
83
        if you reimplement it.
84
    */
85
    void slotUploadFinished(bool result);  
86
87
signals:
88
    void installFinished();
89
    
90
protected:
91
   /** Installs the resource specified by m_tarName. Implement it in the subclass. */
92
    virtual void installResource() = 0;
93
    /** Removes the temporary directory m_tempDir. */
94
    void removeTempDirectory();    
95
    
96
    KTempDir *m_tempDir;
97
    TQString m_tarName; 
98
    TQString m_signedFileName;
99
    TQMap<TQString, TQString> m_installedResources;
100
};
101
102
#endif
(-)tdewebdev/lib/compatibility/knewstuff/provider.cpp (-223 lines)
Lines 1-223 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include <tdeconfig.h>
22
#include <kdebug.h>
23
#include <tdeio/job.h>
24
#include <tdeglobal.h>
25
#include <tdemessagebox.h>
26
#include <tdelocale.h>
27
28
#include "provider.h"
29
#include "provider.moc"
30
31
using namespace KNS;
32
33
Provider::Provider() : mNoUpload( false )
34
{
35
}
36
37
Provider::Provider( const TQDomElement &e ) : mNoUpload( false )
38
{
39
  parseDomElement( e );
40
}
41
42
Provider::~Provider()
43
{
44
}
45
46
47
void Provider::setName( const TQString &name )
48
{
49
  mName = name;
50
}
51
52
TQString Provider::name() const
53
{
54
  return mName;
55
}
56
57
58
void Provider::setIcon( const KURL &url )
59
{
60
  mIcon = url;
61
}
62
63
KURL Provider::icon() const
64
{
65
  return mIcon;
66
}
67
68
69
void Provider::setDownloadUrl( const KURL &url )
70
{
71
  mDownloadUrl = url;
72
}
73
74
KURL Provider::downloadUrl() const
75
{
76
  return mDownloadUrl;
77
}
78
79
80
void Provider::setUploadUrl( const KURL &url )
81
{
82
  mUploadUrl = url;
83
}
84
85
KURL Provider::uploadUrl() const
86
{
87
  return mUploadUrl;
88
}
89
90
91
void Provider::setNoUploadUrl( const KURL &url )
92
{
93
  mNoUploadUrl = url;
94
}
95
96
KURL Provider::noUploadUrl() const
97
{
98
  return mNoUploadUrl;
99
}
100
101
102
void Provider::setNoUpload( bool enabled )
103
{
104
  mNoUpload = enabled;
105
}
106
107
bool Provider::noUpload() const
108
{
109
  return mNoUpload;
110
}
111
112
113
void Provider::parseDomElement( const TQDomElement &element )
114
{
115
  if ( element.tagName() != "provider" ) return;
116
117
  setDownloadUrl( KURL( element.attribute("downloadurl") ) );
118
  setUploadUrl( KURL( element.attribute("uploadurl") ) );
119
  setNoUploadUrl( KURL( element.attribute("nouploadurl") ) );
120
  setIcon( KURL( element.attribute("icon") ) );
121
122
  TQDomNode n;
123
  for ( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
124
    TQDomElement p = n.toElement();
125
    
126
    if ( p.tagName() == "noupload" ) setNoUpload( true );
127
    if ( p.tagName() == "title" ) setName( p.text().stripWhiteSpace() );
128
  }
129
}
130
131
TQDomElement Provider::createDomElement( TQDomDocument &doc, TQDomElement &parent )
132
{
133
  TQDomElement entry = doc.createElement( "stuff" );
134
  parent.appendChild( entry );
135
136
  TQDomElement n = doc.createElement( "name" );
137
  n.appendChild( doc.createTextNode( name() ) );
138
  entry.appendChild( n );
139
  
140
  return entry;
141
}
142
143
144
ProviderLoader::ProviderLoader( TQWidget *parentWidget ) :
145
  mParentWidget( parentWidget )
146
{
147
  mProviders.setAutoDelete( true );
148
}
149
150
void ProviderLoader::load( const TQString &type, const TQString &providersList )
151
{
152
  kdDebug(5850) << "ProviderLoader::load()" << endl;
153
154
  mProviders.clear();
155
  mJobData = "";
156
157
  TDEConfig *cfg = TDEGlobal::config();
158
  cfg->setGroup("KNewStuff");
159
160
  TQString providersUrl = providersList;
161
  if( providersUrl.isEmpty() )
162
  	providersUrl = cfg->readEntry( "ProvidersUrl" );
163
164
  if ( providersUrl.isEmpty() ) {
165
    // TODO: Replace the default by the real one.
166
    TQString server = cfg->readEntry( "MasterServer",
167
                                     "http://korganizer.kde.org" );
168
  
169
    providersUrl = server + "/knewstuff/" + type + "/providers.xml";
170
  }
171
172
  kdDebug(5850) << "ProviderLoader::load(): providersUrl: " << providersUrl << endl;
173
  
174
  TDEIO::TransferJob *job = TDEIO::get( KURL( providersUrl ) );
175
  connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
176
           TQT_SLOT( slotJobResult( TDEIO::Job * ) ) );
177
  connect( job, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ),
178
           TQT_SLOT( slotJobData( TDEIO::Job *, const TQByteArray & ) ) );
179
180
//  job->dumpObjectInfo();
181
}
182
183
void ProviderLoader::slotJobData( TDEIO::Job *, const TQByteArray &data )
184
{
185
  kdDebug(5850) << "ProviderLoader::slotJobData()" << endl;
186
187
  if ( data.size() == 0 ) return;
188
189
  TQCString str( data, data.size() + 1 );
190
191
  mJobData.append( TQString::fromUtf8( str ) );
192
}
193
194
void ProviderLoader::slotJobResult( TDEIO::Job *job )
195
{
196
  if ( job->error() ) {
197
    job->showErrorDialog( mParentWidget );
198
  }
199
200
  kdDebug(5850) << "--PROVIDERS-START--" << endl << mJobData << "--PROV_END--"
201
            << endl;
202
203
  TQDomDocument doc;
204
  if ( !doc.setContent( mJobData ) ) {
205
    KMessageBox::error( mParentWidget, i18n("Error parsing providers list.") );
206
    return;
207
  }
208
209
  TQDomElement providers = doc.documentElement();
210
211
  if ( providers.isNull() ) {
212
    kdDebug(5850) << "No document in Providers.xml." << endl;
213
  }
214
215
  TQDomNode n;
216
  for ( n = providers.firstChild(); !n.isNull(); n = n.nextSibling() ) {
217
    TQDomElement p = n.toElement();
218
    
219
    mProviders.append( new Provider( p ) );
220
  }
221
  
222
  emit providersLoaded( &mProviders );
223
}
(-)tdewebdev/lib/compatibility/knewstuff/provider.h (-207 lines)
Lines 1-207 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_PROVIDER_H
21
#define KNEWSTUFF_PROVIDER_H
22
23
#include <tqcstring.h>
24
#include <tqdom.h>
25
#include <tqobject.h>
26
#include <tqptrlist.h>
27
#include <tqstring.h>
28
29
#include <kurl.h>
30
31
namespace TDEIO { class Job; }
32
33
namespace KNS {
34
35
/**
36
 * @short KNewStuff provider container.
37
 *
38
 * This class provides accessors for the provider object.
39
 * as used by KNewStuff.
40
 * It should probably not be used directly by the application.
41
 *
42
 * @author Cornelius Schumacher (schumacher@kde.org)
43
 * \par Maintainer:
44
 * Josef Spillner (spillner@kde.org)
45
 */
46
class Provider
47
{
48
  public:
49
    typedef TQPtrList<Provider> List;
50
51
    /**
52
     * Constructor.
53
     */
54
    Provider();
55
56
    /**
57
     * Constructor with XML feed.
58
     */
59
    Provider( const TQDomElement & );
60
61
    /**
62
     * Destructor.
63
     */
64
    ~Provider();
65
66
    /**
67
     * Sets the common name of the provider.
68
     */
69
    void setName( const TQString & );
70
71
    /**
72
     * Retrieves the common name of the provider.
73
     *
74
     * @return provider name
75
     */
76
    TQString name() const;
77
78
    /**
79
     * Sets the download URL.
80
     */
81
    void setDownloadUrl( const KURL & );
82
83
    /**
84
     * Retrieves the download URL.
85
     *
86
     * @return download URL
87
     */
88
    KURL downloadUrl() const;
89
90
    /**
91
     * Sets the upload URL.
92
     */
93
    void setUploadUrl( const KURL & );
94
95
    /**
96
     * Retrieves the upload URL.
97
     *
98
     * @return upload URL
99
     */
100
    KURL uploadUrl() const;
101
102
    /**
103
     * Sets the URL where a user is led if the provider does not support
104
     * uploads.
105
     *
106
     * @see setNoUpload
107
     */
108
    void setNoUploadUrl( const KURL & );
109
110
    /**
111
     * Retrieves the URL where a user is led if the provider does not
112
     * support uploads.
113
     *
114
     * @return website URL
115
     */
116
    KURL noUploadUrl() const;
117
118
    /**
119
     * Indicate whether provider supports uploads.
120
     */
121
    void setNoUpload( bool );
122
123
    /**
124
     * Query whether provider supports uploads.
125
     *
126
     * @return upload support status
127
     */
128
    bool noUpload() const;
129
130
    /**
131
     * Sets the URL for an icon for this provider.
132
     * The icon should be in 32x32 format. If not set, the default icon
133
     * of KDialogBase is used.
134
     */
135
    void setIcon( const KURL & );
136
137
    /**
138
     * Retrieves the icon URL for this provider.
139
     *
140
     * @return icon URL
141
     */
142
    KURL icon() const;
143
144
  protected:
145
    void parseDomElement( const TQDomElement & );
146
147
    TQDomElement createDomElement( TQDomDocument &, TQDomElement &parent );
148
149
  private:
150
    TQString mName;
151
    KURL mDownloadUrl;
152
    KURL mUploadUrl;
153
    KURL mNoUploadUrl;
154
    KURL mIcon;
155
    bool mNoUpload;
156
};
157
158
/**
159
 * KNewStuff provider loader.
160
 * This class sets up a list of all possible providers by querying
161
 * the main provider database for this specific application.
162
 * It should probably not be used directly by the application.
163
 */
164
class ProviderLoader : public TQObject
165
{
166
    Q_OBJECT
167
  
168
  public:
169
    /**
170
     * Constructor.
171
     *
172
     * @param parentWidget the parent widget
173
     */
174
    ProviderLoader( TQWidget *parentWidget );
175
176
    /**
177
     * Starts asynchronously loading the list of providers of the
178
     * specified type.
179
     *
180
     * @param type data type such as 'kdesktop/wallpaper'.
181
     * @param providerList the URl to the list of providers; if empty
182
     *    we first try the ProvidersUrl from TDEGlobal::config, then we
183
     *    fall back to a hardcoded value.
184
     */
185
    void load( const TQString &type, const TQString &providerList = TQString() );
186
187
  signals:
188
    /**
189
     * Indicates that the list of providers has been successfully loaded.
190
     */
191
    void providersLoaded( Provider::List * );
192
193
  protected slots:
194
    void slotJobData( TDEIO::Job *, const TQByteArray & );
195
    void slotJobResult( TDEIO::Job * );
196
197
  private:
198
    TQWidget *mParentWidget;
199
200
    TQString mJobData;
201
202
    Provider::List mProviders;
203
};
204
205
}
206
207
#endif
(-)tdewebdev/lib/compatibility/knewstuff/providerdialog.cpp (-95 lines)
Lines 1-95 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include <tqlayout.h>
22
#include <tqstring.h>
23
#include <tqlabel.h>
24
25
#include <tdelistview.h>
26
#include <tdelocale.h>
27
#include <tdemessagebox.h>
28
29
#include "engine.h"
30
#include "provider.h"
31
32
#include "providerdialog.h"
33
#include "providerdialog.moc"
34
35
using namespace KNS;
36
37
class ProviderItem : public TDEListViewItem
38
{
39
  public:
40
    ProviderItem( TDEListView *parent, Provider *provider ) :
41
      TDEListViewItem( parent ), mProvider( provider )
42
    {
43
      setText( 0, provider->name() );
44
    }
45
46
    Provider *provider() { return mProvider; }
47
48
  private:
49
    Provider *mProvider;
50
};
51
52
ProviderDialog::ProviderDialog( Engine *engine, TQWidget *parent ) :
53
  KDialogBase( Plain, i18n("Hot New Stuff Providers"), Ok | Cancel, Cancel,
54
               parent, 0, false, true ),
55
  mEngine( engine )
56
{
57
  TQFrame *topPage = plainPage();
58
59
  TQBoxLayout *topLayout = new TQVBoxLayout( topPage );
60
61
  TQLabel *description = new TQLabel( i18n("Please select one of the providers listed below:"), topPage );
62
  topLayout->addWidget( description );
63
64
  mListView = new TDEListView( topPage );
65
  mListView->addColumn( i18n("Name") );
66
  topLayout->addWidget( mListView );
67
}
68
69
void ProviderDialog::clear()
70
{
71
  mListView->clear();
72
}
73
74
void ProviderDialog::addProvider( Provider *provider )
75
{
76
  new ProviderItem( mListView, provider );
77
  if ( mListView->childCount() == 1 ) {
78
    mListView->setSelected(mListView->firstChild(), true);
79
  } else if (mListView->childCount() > 1) {
80
    mListView->setSelected(mListView->firstChild(), false);
81
  }
82
}
83
84
void ProviderDialog::slotOk()
85
{
86
  ProviderItem *item = static_cast<ProviderItem *>( mListView->selectedItem() );
87
  if ( !item ) {
88
    KMessageBox::error( this, i18n("No provider selected.") );
89
    return;
90
  }
91
92
  mEngine->requestMetaInformation( item->provider() );
93
94
  accept();
95
}
(-)tdewebdev/lib/compatibility/knewstuff/providerdialog.h (-77 lines)
Lines 1-77 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_PROVIDERDIALOG_H
21
#define KNEWSTUFF_PROVIDERDIALOG_H
22
23
#include <kdialogbase.h>
24
25
class TDEListView;
26
27
namespace KNS {
28
29
class Provider;
30
class Engine;
31
32
/**
33
 * @short Dialog displaying a list of Hotstuff providers.
34
 *
35
 * This is normally used in the process of uploading data, thus limiting the
36
 * list to providers which support uploads.
37
 * One of the providers is then chosen by the user for further operation.
38
 *
39
 * @author Cornelius Schumacher (schumacher@kde.org)
40
 * \par Maintainer:
41
 * Josef Spillner (spillner@kde.org)
42
 */
43
class ProviderDialog : public KDialogBase
44
{
45
    Q_OBJECT
46
  
47
  public:
48
    /**
49
      Constructor.
50
51
      @param engine a KNewStuff engine object
52
      @param parent the parent window
53
    */
54
    ProviderDialog( Engine *engine, TQWidget *parent );
55
56
    /**
57
      Clears the list of providers.
58
    */
59
    void clear();
60
61
    /**
62
      Adds a Hotstuff provider to the list.
63
    */
64
    void addProvider( Provider * );
65
66
  protected slots:
67
    void slotOk();
68
69
  private:
70
    Engine *mEngine;
71
72
    TDEListView *mListView;
73
};
74
75
}
76
77
#endif
(-)tdewebdev/lib/compatibility/knewstuff/security.cpp (-344 lines)
Lines 1-344 Link Here
1
/***************************************************************************
2
                          security.cpp  -  description
3
                             -------------------
4
    begin                : Thu Jun 24 11:22:12 2004
5
    copyright          : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
6
 ***************************************************************************/
7
8
/***************************************************************************
9
 *                                                                         *
10
 *   This program is free software; you can redistribute it and/or modify  *
11
 *   it under the terms of the GNU Library General Public License as       *
12
 *   published by the Free Software Foundation; version 2 of the License.  *
13
 *                                                                         *
14
 ***************************************************************************/
15
16
 //qt includes
17
#include <tqfile.h>
18
#include <tqfileinfo.h>
19
#include <tqstringlist.h>
20
#include <tqtimer.h>
21
22
 //kde includes
23
#include <kdebug.h>
24
#include <kinputdialog.h>
25
#include <tdelocale.h>
26
#include <kmdcodec.h>
27
#include <tdemessagebox.h>
28
#include <kpassdlg.h>
29
#include <kprocio.h>
30
31
 //app includes
32
#include "security.h"
33
34
using namespace KNS;
35
36
Security::Security()
37
{
38
   m_keysRead = false;
39
   m_gpgRunning = false;
40
   readKeys();
41
   readSecretKeys();
42
}
43
44
45
Security::~Security()
46
{
47
}
48
49
void Security::readKeys()
50
{
51
  if (m_gpgRunning)
52
  {
53
    TQTimer::singleShot(5, this, TQT_SLOT(readKeys()));
54
    return;
55
  }
56
  m_runMode = List;
57
  m_keys.clear();
58
  KProcIO *readProcess=new KProcIO();
59
  *readProcess << "gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--with-colon"<<"--list-keys";
60
  connect(readProcess, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotProcessExited(TDEProcess *)));
61
  connect(readProcess, TQT_SIGNAL(readReady(KProcIO *)) ,this, TQT_SLOT(slotDataArrived(KProcIO *)));
62
  if (!readProcess->start(TDEProcess::NotifyOnExit, true))
63
    KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and retrieve the available keys. Make sure that <i>gpg</i> is installed, otherwise verification of downloaded resources will not be possible.</qt>"));
64
  else
65
    m_gpgRunning = true;
66
}
67
68
void Security::readSecretKeys()
69
{
70
  if (m_gpgRunning)
71
  {
72
    TQTimer::singleShot(5, this, TQT_SLOT(readSecretKeys()));
73
    return;
74
  }
75
  m_runMode = ListSecret;
76
  KProcIO *readProcess=new KProcIO();
77
  *readProcess << "gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--with-colon"<<"--list-secret-keys";
78
  connect(readProcess, TQT_SIGNAL(processExited(TDEProcess *)), this, TQT_SLOT(slotProcessExited(TDEProcess *)));
79
  connect(readProcess, TQT_SIGNAL(readReady(KProcIO *)) ,this, TQT_SLOT(slotDataArrived(KProcIO *)));
80
  if (readProcess->start(TDEProcess::NotifyOnExit, true))
81
    m_gpgRunning = true;  
82
}
83
84
void Security::slotProcessExited(TDEProcess *process)
85
{
86
  switch (m_runMode)
87
   {
88
     case ListSecret:
89
                  m_keysRead = true;
90
                  break;
91
     case Verify: emit validityResult(m_result);
92
                  break;
93
     case Sign:   emit fileSigned(m_result);
94
                  break;
95
96
   }
97
   m_gpgRunning = false;
98
   delete process;
99
}
100
101
void Security::slotDataArrived(KProcIO *procIO)
102
{
103
  TQString data;
104
  while (procIO->readln(data, true) != -1)
105
  {
106
     switch (m_runMode)
107
     {
108
        case List:
109
        case ListSecret:  
110
          if (data.startsWith("pub") || data.startsWith("sec"))
111
          {
112
              KeyStruct key;
113
              if (data.startsWith("pub"))
114
                key.secret = false;
115
              else
116
                key.secret = true;
117
              TQStringList line = TQStringList::split(":", data, true);
118
              key.id = line[4];
119
              TQString shortId = key.id.right(8);
120
              TQString trustStr = line[1];
121
              key.trusted = false;
122
              if (trustStr == "u" || trustStr == "f")
123
                  key.trusted = true;
124
              data = line[9];
125
              key.mail=data.section('<', -1, -1);
126
              key.mail.truncate(key.mail.length() - 1);
127
              key.name=data.section('<',0,0);
128
              if (key.name.find("(")!=-1)
129
                  key.name=key.name.section('(',0,0);
130
              m_keys[shortId] = key;
131
          }
132
          break;
133
       case Verify:
134
          data = data.section("]",1,-1).stripWhiteSpace();
135
          if (data.startsWith("GOODSIG"))
136
          {
137
              m_result &= SIGNED_BAD_CLEAR;
138
              m_result |= SIGNED_OK;
139
              TQString id = data.section(" ", 1 , 1).right(8);
140
              if (!m_keys.contains(id))
141
              {
142
                  m_result |= UNKNOWN;
143
              } else
144
              {
145
                 m_signatureKey = m_keys[id];
146
              }
147
          } else
148
          if (data.startsWith("NO_PUBKEY"))
149
          {
150
              m_result &= SIGNED_BAD_CLEAR;
151
              m_result |= UNKNOWN;
152
          } else
153
          if (data.startsWith("BADSIG"))
154
          {
155
              m_result |= SIGNED_BAD;
156
              TQString id = data.section(" ", 1 , 1).right(8);
157
              if (!m_keys.contains(id))
158
              {
159
                  m_result |= UNKNOWN;
160
              } else
161
              {
162
                 m_signatureKey = m_keys[id];
163
              }
164
          } else
165
          if (data.startsWith("TRUST_ULTIMATE"))
166
          {
167
            m_result &= SIGNED_BAD_CLEAR;
168
            m_result |= TRUSTED;
169
          }
170
          break;
171
172
       case Sign:
173
         if (data.find("passphrase.enter") != -1)
174
         {
175
           TQCString password;
176
           KeyStruct key = m_keys[m_secretKey];
177
           int result = KPasswordDialog::getPassword(password, i18n("<qt>Enter passphrase for key <b>0x%1</b>, belonging to<br><i>%2&lt;%3&gt;</i>:</qt>").arg(m_secretKey).arg(key.name).arg(key.mail));
178
           if (result == KPasswordDialog::Accepted)
179
           {
180
             procIO->writeStdin(password, true);
181
             password.fill(' ');
182
           }
183
           else
184
           {
185
             m_result |= BAD_PASSPHRASE;
186
             slotProcessExited(procIO);
187
             return;
188
           }
189
         } else
190
         if (data.find("BAD_PASSPHRASE") != -1)
191
         {
192
           m_result |= BAD_PASSPHRASE;
193
         }
194
         break;
195
     }
196
  }
197
}
198
199
void Security::checkValidity(const TQString& filename)
200
{
201
  m_fileName = filename;
202
  slotCheckValidity();
203
}  
204
205
void Security::slotCheckValidity()
206
{  
207
  if (!m_keysRead || m_gpgRunning)
208
  {
209
    TQTimer::singleShot(5, this, TQT_SLOT(slotCheckValidity()));
210
    return;
211
  }
212
  if (m_keys.count() == 0)
213
  {    
214
    emit validityResult(-1);
215
    return;
216
  }  
217
218
  m_result = 0;
219
  m_runMode = Verify;
220
  TQFileInfo f(m_fileName);
221
  //check the MD5 sum
222
  TQString md5sum;
223
  const char* c = "";
224
  KMD5 context(c);
225
  TQFile file(m_fileName);
226
  if (file.open(IO_ReadOnly))
227
  {
228
     context.reset();
229
     context.update(file);
230
     md5sum = context.hexDigest();
231
     file.close();
232
  }
233
  file.setName(f.dirPath() + "/md5sum");
234
  if (file.open(IO_ReadOnly))
235
  {
236
     TQString md5sum_file;
237
     file.readLine(md5sum_file, 50);
238
     if (!md5sum.isEmpty() && !md5sum_file.isEmpty() && md5sum_file.startsWith(md5sum))
239
       m_result |= MD5_OK;
240
     file.close();
241
  }
242
  m_result |= SIGNED_BAD;
243
  m_signatureKey.id = "";
244
  m_signatureKey.name = "";
245
  m_signatureKey.mail = "";
246
  m_signatureKey.trusted = false;
247
248
  //verify the signature
249
  KProcIO *verifyProcess=new KProcIO();
250
  *verifyProcess<<"gpg"<<"--no-secmem-warning"<<"--status-fd=2"<<"--command-fd=0"<<"--verify" << f.dirPath() + "/signature"<< m_fileName;
251
  connect(verifyProcess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotProcessExited(TDEProcess *)));
252
  connect(verifyProcess, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotDataArrived(KProcIO *)));
253
  if (verifyProcess->start(TDEProcess::NotifyOnExit,true))
254
      m_gpgRunning = true;
255
  else
256
  {
257
      KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and check the validity of the file. Make sure that <i>gpg</i> is installed, otherwise verification of downloaded resources will not be possible.</qt>"));
258
      emit validityResult(0);
259
      delete verifyProcess;
260
  }
261
}
262
263
void Security::signFile(const TQString &fileName)
264
{
265
  m_fileName = fileName;
266
  slotSignFile();
267
}
268
269
void Security::slotSignFile()
270
{
271
  if (!m_keysRead || m_gpgRunning)
272
  {
273
    TQTimer::singleShot(5, this, TQT_SLOT(slotSignFile()));
274
    return;
275
  }
276
  
277
  TQStringList secretKeys;
278
  for (TQMap<TQString, KeyStruct>::Iterator it = m_keys.begin(); it != m_keys.end(); ++it)
279
  {
280
    if (it.data().secret)
281
      secretKeys.append(it.key());
282
  }
283
  
284
  if (secretKeys.count() == 0)
285
  {    
286
    emit fileSigned(-1);
287
    return;
288
  }  
289
  
290
  m_result = 0;
291
  TQFileInfo f(m_fileName);
292
293
  //create the MD5 sum
294
  TQString md5sum;
295
  const char* c = "";
296
  KMD5 context(c);
297
  TQFile file(m_fileName);
298
  if (file.open(IO_ReadOnly))
299
  {
300
    context.reset();
301
    context.update(file);
302
    md5sum = context.hexDigest();
303
    file.close();
304
  }
305
  file.setName(f.dirPath() + "/md5sum");
306
  if (file.open(IO_WriteOnly))
307
  {
308
    TQTextStream stream(&file);
309
    stream << md5sum;
310
    m_result |= MD5_OK;
311
    file.close();
312
  }
313
  
314
  if (secretKeys.count() > 1)
315
  {
316
    bool ok;
317
    secretKeys = KInputDialog::getItemList(i18n("Select Signing Key"), i18n("Key used for signing:"), secretKeys, secretKeys[0], false, &ok);    
318
    if (ok)
319
      m_secretKey = secretKeys[0];
320
    else
321
    {
322
      emit fileSigned(0);
323
      return;
324
    }
325
  } else
326
    m_secretKey = secretKeys[0];
327
328
  //verify the signature
329
  KProcIO *signProcess=new KProcIO();
330
  *signProcess<<"gpg"<<"--no-secmem-warning"<<"--status-fd=2"<<"--command-fd=0"<<"--no-tty"<<"--detach-sign" << "-u" << m_secretKey << "-o" << f.dirPath() + "/signature" << m_fileName;
331
  connect(signProcess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotProcessExited(TDEProcess *)));
332
  connect(signProcess, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotDataArrived(KProcIO *)));
333
  m_runMode = Sign;
334
  if (signProcess->start(TDEProcess::NotifyOnExit,true))
335
    m_gpgRunning = true;
336
  else
337
  {
338
    KMessageBox::error(0L, i18n("<qt>Cannot start <i>gpg</i> and sign the file. Make sure that <i>gpg</i> is installed, otherwise signing of the resources will not be possible.</qt>"));
339
    emit fileSigned(0);
340
    delete signProcess;
341
  }
342
}
343
344
#include "security.moc"
(-)tdewebdev/lib/compatibility/knewstuff/security.h (-142 lines)
Lines 1-142 Link Here
1
/***************************************************************************
2
                          security.h  -  description
3
                             -------------------
4
    begin                : Thu Jun 24 11:22:12 2004
5
    copyright          : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
6
 ***************************************************************************/
7
8
/***************************************************************************
9
 *                                                                         *
10
 *   This program is free software; you can redistribute it and/or modify  *
11
 *   it under the terms of the GNU Library General Public License as       *
12
 *   published by the Free Software Foundation; version 2 of the License.  *
13
 *                                                                         *
14
 ***************************************************************************/
15
16
17
#ifndef SECURITY_H
18
#define SECURITY_H
19
20
//qt includes
21
#include <tqmap.h>
22
#include <tqobject.h>
23
24
class KProcIO;
25
class TDEProcess;
26
27
struct KeyStruct {
28
   TQString id;
29
   TQString name;
30
   TQString mail;
31
   bool trusted;
32
   bool secret;
33
};
34
35
/**
36
Handles security releated issues, like signing, verifying.
37
It is a private class, not meant to be used by third party applications.
38
39
@author Andras Mantia <amantia@kde.org>
40
*/
41
42
namespace KNS {
43
44
class Security : public TQObject
45
{
46
Q_OBJECT
47
  
48
public:
49
  static Security* const ref()
50
  {
51
    static Security *m_ref;
52
    if (!m_ref) m_ref = new Security();
53
    return m_ref;
54
  }
55
  ~Security();
56
57
58
  /** Verifies the integrity and the signature of a tarball file.
59
   * @param fileName the file to be verified. It should be a tar.gz (.tgz) file. The directory where
60
   *               the file is should contain a "signature" and a "md5sum" file, otherwise verification will fail.
61
   *               The method is asynchronous and the result is signalled with @ref validityResult.
62
   */
63
  void checkValidity(const TQString &fileName);
64
65
  /** Creates a signature and an md5sum file for the fileName and packs
66
   * everything into a gzipped tarball.
67
   * @param fileName the file with full path to sign
68
   *
69
   * The method is asynchronous and the result is signalled with @ref fileSigned.
70
   */
71
  void signFile(const TQString &fileName);
72
  /** Get the key used for signing. This method is valid only if:
73
  *  - the checkValidity was called
74
  *  - the result of the validity check does not have the UNKNOWN bit set
75
  *
76
  *  @return the key used for signing the file
77
  */
78
  KeyStruct signatureKey() {return m_signatureKey;}
79
80
  enum Results {
81
     MD5_OK = 1, /// The MD5 sum check is OK
82
     SIGNED_OK = 2, /// The file is signed with a good signature
83
     SIGNED_BAD = 4, /// The file is signed with a bad signature
84
     TRUSTED = 8, /// The signature is trusted
85
     UNKNOWN = 16, ///The key is unknown
86
     SIGNED_BAD_CLEAR = 27, ///used to clear the SIGNED_BAD flag
87
     BAD_PASSPHRASE = 32 ///wrong passhprase entered
88
  };
89
90
public slots:
91
  /** Reads the available public keys */
92
  void readKeys();
93
  /** Reads the available secret keys */
94
  void readSecretKeys();
95
  /** Verifies the integrity and the signature of a tarball file (@see m_fileName).
96
   */
97
  void slotCheckValidity();
98
99
  /** Creates a signature and an md5sum file for the @see m_fileName and packs
100
   * everything into a gzipped tarball.
101
   */
102
  void slotSignFile();
103
104
private:
105
   Security();
106
107
   enum RunMode {
108
       List = 0, ///read the public keys
109
       ListSecret, ///read the secret keys
110
       Verify, ///verify the signature
111
       Sign ///create signature
112
   };
113
114
   KeyStruct m_signatureKey;
115
   int m_result;
116
   int m_runMode;
117
   bool m_gpgRunning; /// true if gpg is currently running
118
   bool m_keysRead; /// true if all the keys were read
119
   TQMap<TQString, KeyStruct> m_keys; /// holds information about the available key
120
   TQString m_fileName; /// the file to sign/verify
121
   TQString m_secretKey; /// the key used for signing
122
123
private slots:
124
   void slotProcessExited(TDEProcess *process);
125
   void slotDataArrived(KProcIO *process);
126
127
signals:
128
   /** Sent when the validity check is done.
129
   *
130
   *    @return the result of the check. See @ref Results
131
   */
132
    void validityResult(int result);
133
   /** Sent when the signing is done.
134
     *
135
     *    @return the result of the operation. See @ref Results
136
    */
137
    void fileSigned(int result);
138
};
139
140
}
141
142
#endif
(-)tdewebdev/lib/compatibility/knewstuff/uploaddialog.cpp (-176 lines)
Lines 1-176 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
21
#include <tqcombobox.h>
22
#include <tqlabel.h>
23
#include <tqlayout.h>
24
#include <tqlineedit.h>
25
#include <tqspinbox.h>
26
#include <tqstring.h>
27
#include <ktextedit.h>
28
29
#include <tdelistview.h>
30
#include <tdelocale.h>
31
#include <kdebug.h>
32
#include <kurlrequester.h>
33
#include <tdemessagebox.h>
34
#include <tdeconfig.h>
35
#include <tdeapplication.h>
36
37
#include "engine.h"
38
#include "entry.h"
39
40
#include "uploaddialog.h"
41
#include "uploaddialog.moc"
42
43
using namespace KNS;
44
45
UploadDialog::UploadDialog( Engine *engine, TQWidget *parent ) :
46
  KDialogBase( Plain, i18n("Share Hot New Stuff"), Ok | Cancel, Cancel,
47
               parent, 0, false, true ),
48
  mEngine( engine )
49
{
50
  mEntryList.setAutoDelete( true );
51
52
  TQFrame *topPage = plainPage();
53
54
  TQGridLayout *topLayout = new TQGridLayout( topPage );
55
  topLayout->setSpacing( spacingHint() );
56
57
  TQLabel *nameLabel = new TQLabel( i18n("Name:"), topPage );
58
  topLayout->addWidget( nameLabel, 0, 0 );  
59
  mNameEdit = new TQLineEdit( topPage );
60
  topLayout->addWidget( mNameEdit, 0, 1 );
61
62
  TQLabel *authorLabel = new TQLabel( i18n("Author:"), topPage );
63
  topLayout->addWidget( authorLabel, 1, 0 );
64
  mAuthorEdit = new TQLineEdit( topPage );
65
  topLayout->addWidget( mAuthorEdit, 1, 1 );
66
67
  TQLabel *versionLabel = new TQLabel( i18n("Version:"), topPage );
68
  topLayout->addWidget( versionLabel, 2, 0 );  
69
  mVersionEdit = new TQLineEdit( topPage );
70
  topLayout->addWidget( mVersionEdit, 2, 1 );
71
72
  TQLabel *releaseLabel = new TQLabel( i18n("Release:"), topPage );
73
  topLayout->addWidget( releaseLabel, 3, 0 );  
74
  mReleaseSpin = new TQSpinBox( topPage );
75
  mReleaseSpin->setMinValue( 1 );
76
  topLayout->addWidget( mReleaseSpin, 3, 1 );
77
78
  TQLabel *licenceLabel = new TQLabel( i18n("License:"), topPage );
79
  topLayout->addWidget( licenceLabel, 4, 0 );
80
  mLicenceCombo = new TQComboBox( topPage );
81
  mLicenceCombo->setEditable( true );
82
  mLicenceCombo->insertItem( i18n("GPL") );
83
  mLicenceCombo->insertItem( i18n("LGPL") );
84
  mLicenceCombo->insertItem( i18n("BSD") );
85
  topLayout->addWidget( mLicenceCombo, 4, 1 );
86
87
  TQLabel *languageLabel = new TQLabel( i18n("Language:"), topPage );
88
  topLayout->addWidget( languageLabel, 5, 0 );
89
  mLanguageCombo = new TQComboBox( topPage );
90
  topLayout->addWidget( mLanguageCombo, 5, 1 );
91
  mLanguageCombo->insertStringList( TDEGlobal::locale()->languageList() );
92
93
  TQLabel *previewLabel = new TQLabel( i18n("Preview URL:"), topPage );
94
  topLayout->addWidget( previewLabel, 6, 0 );
95
  mPreviewUrl = new KURLRequester( topPage );
96
  topLayout->addWidget( mPreviewUrl, 6, 1 );
97
98
  TQLabel *summaryLabel = new TQLabel( i18n("Summary:"), topPage );
99
  topLayout->addMultiCellWidget( summaryLabel, 7, 7, 0, 1 );
100
  mSummaryEdit = new KTextEdit( topPage );
101
  topLayout->addMultiCellWidget( mSummaryEdit, 8, 8, 0, 1 );
102
103
  TDEConfig *conf = kapp->config();
104
  conf->setGroup("KNewStuffUpload");
105
  TQString name = conf->readEntry("name");
106
  TQString author = conf->readEntry("author");
107
  TQString version = conf->readEntry("version");
108
  TQString release = conf->readEntry("release");
109
  TQString preview = conf->readEntry("preview");
110
  TQString summary = conf->readEntry("summary");
111
  TQString lang = conf->readEntry("language");
112
  TQString licence = conf->readEntry("licence");
113
114
  if(!name.isNull())
115
  {
116
    int prefill = KMessageBox::questionYesNo(this, i18n("Old upload information found, fill out fields?"), TQString(), i18n("Fill Out Fields"), i18n("Do Not Fill Out"));
117
    if(prefill == KMessageBox::Yes)
118
    {
119
      mNameEdit->setText(name);
120
      mAuthorEdit->setText(author);
121
      mVersionEdit->setText(version);
122
      mReleaseSpin->setValue(release.toInt());
123
      mPreviewUrl->setURL(preview);
124
      mSummaryEdit->setText(summary);
125
      if(!lang.isEmpty()) mLanguageCombo->setCurrentText(lang);
126
      if(!licence.isEmpty()) mLicenceCombo->setCurrentText(licence);
127
    }
128
  }
129
}
130
131
UploadDialog::~UploadDialog()
132
{
133
  mEntryList.clear();
134
}
135
136
void UploadDialog::slotOk()
137
{
138
  if ( mNameEdit->text().isEmpty() ) {
139
    KMessageBox::error( this, i18n("Please put in a name.") );
140
    return;
141
  }
142
143
  Entry *entry = new Entry;
144
145
  mEntryList.append( entry );
146
147
  entry->setName( mNameEdit->text() );
148
  entry->setAuthor( mAuthorEdit->text() );
149
  entry->setVersion( mVersionEdit->text() );
150
  entry->setRelease( mReleaseSpin->value() );
151
  entry->setLicence( mLicenceCombo->currentText() );
152
  entry->setPreview( KURL( mPreviewUrl->url().section("/", -1) ), mLanguageCombo->currentText() );
153
  entry->setSummary( mSummaryEdit->text(), mLanguageCombo->currentText() );
154
155
  TDEConfig *conf = kapp->config();
156
  conf->setGroup("KNewStuffUpload");
157
  conf->writeEntry("name", mNameEdit->text());
158
  conf->writeEntry("author", mAuthorEdit->text());
159
  conf->writeEntry("version", mVersionEdit->text());
160
  conf->writeEntry("release", mReleaseSpin->value());
161
  conf->writeEntry("licence", mLicenceCombo->currentText());
162
  conf->writeEntry("preview", mPreviewUrl->url());
163
  conf->writeEntry("summary", mSummaryEdit->text());
164
  conf->writeEntry("language", mLanguageCombo->currentText());
165
  conf->sync();
166
167
  mEngine->upload( entry );
168
169
  accept();
170
}
171
172
void UploadDialog::setPreviewFile( const TQString &previewFile )
173
{
174
  mPreviewUrl->setURL( previewFile );
175
}
176
(-)tdewebdev/lib/compatibility/knewstuff/uploaddialog.h (-93 lines)
Lines 1-93 Link Here
1
/*
2
    This file is part of KOrganizer.
3
    Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Library General Public
7
    License as published by the Free Software Foundation; either
8
    version 2 of the License, or (at your option) any later version.
9
10
    This library is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
    Library General Public License for more details.
14
15
    You should have received a copy of the GNU Library General Public License
16
    along with this library; see the file COPYING.LIB.  If not, write to
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
    Boston, MA 02110-1301, USA.
19
*/
20
#ifndef KNEWSTUFF_UPLOADDIALOG_H
21
#define KNEWSTUFF_UPLOADDIALOG_H
22
23
#include <kdialogbase.h>
24
25
class TQLineEdit;
26
class TQSpinBox;
27
class KURLRequester;
28
class TQTextEdit;
29
class TQComboBox;
30
31
namespace KNS {
32
33
class Engine;
34
class Entry;
35
36
/**
37
 * @short KNewStuff file upload dialog.
38
 *
39
 * Using this dialog, data can easily be uploaded to the Hotstuff servers.
40
 * It should however not be used on its own, instead a KNewStuff (or
41
 * KNewStuffGeneric) object invokes it.
42
 *
43
 * @author Cornelius Schumacher (schumacher@kde.org)
44
 * \par Maintainer:
45
 * Josef Spillner (spillner@kde.org)
46
 */
47
class UploadDialog : public KDialogBase
48
{
49
    Q_OBJECT
50
  
51
  public:
52
    /**
53
      Constructor.
54
55
      @param engine a KNewStuff engine object to be used for uploads
56
      @param parent the parent window
57
    */
58
    UploadDialog( Engine *engine, TQWidget *parent );
59
60
    /**
61
      Destructor.
62
    */
63
    ~UploadDialog();
64
65
    /**
66
      Sets the preview filename.
67
      This is only meaningful if the application supports previews.
68
69
      @param previewFile the preview image file
70
    */
71
    void setPreviewFile( const TQString &previewFile );
72
73
  protected slots:
74
    void slotOk();
75
76
  private:
77
    Engine *mEngine;
78
79
    TQLineEdit *mNameEdit;
80
    TQLineEdit *mAuthorEdit;
81
    TQLineEdit *mVersionEdit;
82
    TQSpinBox *mReleaseSpin;
83
    KURLRequester *mPreviewUrl;
84
    TQTextEdit *mSummaryEdit;
85
    TQComboBox *mLanguageCombo;
86
    TQComboBox *mLicenceCombo;
87
88
    TQPtrList<Entry> mEntryList;
89
};
90
91
}
92
93
#endif
(-)tdewebdev/quanta/data/tips (-1 / +1 lines)
Lines 355-361 Link Here
355
355
356
<tip category="Application">
356
<tip category="Application">
357
<html>
357
<html>
358
<p>...that Quanta now has a <b>public repository</b> for all resources? Quanta uses <i>KNewStuff</i> to make templates, scripts, DTEPs, toolbars and more available for download. Need something? Check the download menu items.
358
<p>...that Quanta now has a <b>public repository</b> for all resources? Quanta uses <i>TDENewStuff</i> to make templates, scripts, DTEPs, toolbars and more available for download. Need something? Check the download menu items.
359
</p>
359
</p>
360
</html>
360
</html>
361
</tip>
361
</tip>
(-)tdewebdev/quanta/src/quanta_init.cpp (-2 / +2 lines)
Lines 617-624 Link Here
617
  m_quanta->showVPLAction->setChecked( false );
617
  m_quanta->showVPLAction->setChecked( false );
618
618
619
619
620
//KNewStuff config
620
//TDENewStuff config
621
   m_config->setGroup("KNewStuff");
621
   m_config->setGroup("TDENewStuff");
622
   TQString str = m_config->readEntry("ProvidersUrl");
622
   TQString str = m_config->readEntry("ProvidersUrl");
623
   if (str.isEmpty())
623
   if (str.isEmpty())
624
   {
624
   {
(-)tdewebdev/quanta/utility/newstuff.cpp (-2 / +2 lines)
Lines 54-60 Link Here
54
}
54
}
55
55
56
QNewToolbarStuff::QNewToolbarStuff(const TQString &type,  TQWidget *parentWidget)
56
QNewToolbarStuff::QNewToolbarStuff(const TQString &type,  TQWidget *parentWidget)
57
  :KNewStuffSecure(type, parentWidget)
57
  :TDENewStuffSecure(type, parentWidget)
58
{
58
{
59
  connect(this, TQT_SIGNAL(loadToolbarFile(const KURL&)), parentWidget, TQT_SLOT(slotLoadToolbarFile(const KURL&)));
59
  connect(this, TQT_SIGNAL(loadToolbarFile(const KURL&)), parentWidget, TQT_SLOT(slotLoadToolbarFile(const KURL&)));
60
}
60
}
Lines 81-87 Link Here
81
}
81
}
82
82
83
QNewTemplateStuff::QNewTemplateStuff(const TQString &type,  TQWidget *parentWidget)
83
QNewTemplateStuff::QNewTemplateStuff(const TQString &type,  TQWidget *parentWidget)
84
  :KNewStuffSecure(type, parentWidget)
84
  :TDENewStuffSecure(type, parentWidget)
85
{
85
{
86
  connect(this, TQT_SIGNAL(openFile(const KURL&)), parentWidget, TQT_SLOT(slotFileOpen(const KURL&)));
86
  connect(this, TQT_SIGNAL(openFile(const KURL&)), parentWidget, TQT_SLOT(slotFileOpen(const KURL&)));
87
}
87
}
(-)tdewebdev/quanta/utility/newstuff.h (-9 / +9 lines)
Lines 20-26 Link Here
20
#include <tqobject.h>
20
#include <tqobject.h>
21
21
22
//kde includes
22
//kde includes
23
#include <knewstuff/knewstuffsecure.h>
23
#include <tdenewstuff/knewstuffsecure.h>
24
/**
24
/**
25
Makes possible downloading and installing a DTEP resource files from a server.
25
Makes possible downloading and installing a DTEP resource files from a server.
26
26
Lines 29-42 Link Here
29
29
30
class KURL;
30
class KURL;
31
31
32
class QNewDTEPStuff: public KNewStuffSecure
32
class QNewDTEPStuff: public TDENewStuffSecure
33
{
33
{
34
   Q_OBJECT
34
   Q_OBJECT
35
  
35
  
36
36
37
public:
37
public:
38
    QNewDTEPStuff(const TQString &type,  TQWidget *parentWidget=0)
38
    QNewDTEPStuff(const TQString &type,  TQWidget *parentWidget=0)
39
      :KNewStuffSecure(type, parentWidget){};
39
      :TDENewStuffSecure(type, parentWidget){};
40
    ~QNewDTEPStuff() {};
40
    ~QNewDTEPStuff() {};
41
41
42
private:
42
private:
Lines 48-54 Link Here
48
48
49
@author Andras Mantia
49
@author Andras Mantia
50
*/
50
*/
51
class QNewToolbarStuff: public KNewStuffSecure
51
class QNewToolbarStuff: public TDENewStuffSecure
52
{
52
{
53
   Q_OBJECT
53
   Q_OBJECT
54
  
54
  
Lines 69-75 Link Here
69
69
70
@author Andras Mantia
70
@author Andras Mantia
71
*/
71
*/
72
class QNewTemplateStuff: public KNewStuffSecure
72
class QNewTemplateStuff: public TDENewStuffSecure
73
{
73
{
74
   Q_OBJECT
74
   Q_OBJECT
75
  
75
  
Lines 90-103 Link Here
90
90
91
@author Andras Mantia
91
@author Andras Mantia
92
*/
92
*/
93
class QNewScriptStuff: public KNewStuffSecure
93
class QNewScriptStuff: public TDENewStuffSecure
94
{
94
{
95
   Q_OBJECT
95
   Q_OBJECT
96
  
96
  
97
97
98
public:
98
public:
99
    QNewScriptStuff(const TQString &type,  TQWidget *parentWidget=0)
99
    QNewScriptStuff(const TQString &type,  TQWidget *parentWidget=0)
100
      :KNewStuffSecure(type, parentWidget){};
100
      :TDENewStuffSecure(type, parentWidget){};
101
    ~QNewScriptStuff() {};
101
    ~QNewScriptStuff() {};
102
102
103
private:
103
private:
Lines 109-122 Link Here
109
109
110
@author Andras Mantia
110
@author Andras Mantia
111
 */
111
 */
112
class QNewDocStuff: public KNewStuffSecure
112
class QNewDocStuff: public TDENewStuffSecure
113
{
113
{
114
  Q_OBJECT
114
  Q_OBJECT
115
  
115
  
116
116
117
  public:
117
  public:
118
    QNewDocStuff(const TQString &type,  TQWidget *parentWidget=0)
118
    QNewDocStuff(const TQString &type,  TQWidget *parentWidget=0)
119
  :KNewStuffSecure(type, parentWidget){};
119
  :TDENewStuffSecure(type, parentWidget){};
120
    ~QNewDocStuff() {};
120
    ~QNewDocStuff() {};
121
121
122
  private:
122
  private:

Return to bug 2127