00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <kapplication.h>
00021 #include <klocale.h>
00022
00023 #include <qlayout.h>
00024 #include <qvbox.h>
00025 #include <kdebug.h>
00026 #include <qlabel.h>
00027 #include <qcombobox.h>
00028
00029 #include <klineedit.h>
00030 #include <kurlrequester.h>
00031 #include <kseparator.h>
00032 #include <kiconloader.h>
00033 #include "koInsertLink.h"
00034 #include <kdesktopfile.h>
00035 #include <krecentdocument.h>
00036
00037 using namespace KOfficePrivate;
00038
00039 KoInsertLinkDia::KoInsertLinkDia( QWidget *parent, const char *name, bool displayBookmarkLink )
00040 : KDialogBase( KDialogBase::IconList, i18n("Insert Link"),
00041 KDialogBase::Ok | KDialogBase::Cancel,
00042 KDialogBase::Ok, parent, name )
00043 {
00044 bookmarkLink = 0L;
00045 QVBox *page=addVBoxPage(i18n("Internet"), QString::null,BarIcon("html",KIcon::SizeMedium));
00046 internetLink = new internetLinkPage(page );
00047 connect(internetLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ( )));
00048
00049 page=addVBoxPage(i18n("Mail & News"), QString::null,BarIcon("mail_generic",KIcon::SizeMedium));
00050 mailLink = new mailLinkPage(page );
00051 connect(mailLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ()));
00052
00053 page=addVBoxPage(i18n("File"), QString::null,BarIcon("filenew",KIcon::SizeMedium));
00054 fileLink = new fileLinkPage(page );
00055 connect(fileLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ()));
00056
00057 if ( displayBookmarkLink)
00058 {
00059 page=addVBoxPage(i18n("Bookmark"), QString::null,BarIcon("bookmark",KIcon::SizeMedium));
00060 bookmarkLink = new bookmarkLinkPage(page );
00061 connect(bookmarkLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ()));
00062 }
00063
00064 connect( this, SIGNAL( aboutToShowPage(QWidget *) ), this, SLOT( tabChanged(QWidget *) ) );
00065
00066 slotTextChanged ( );
00067 resize(400,300);
00068 }
00069
00070 void KoInsertLinkDia::tabChanged(QWidget *)
00071 {
00072 switch( activePageIndex() )
00073 {
00074 case 0:
00075 internetLink->setLinkName( currentText );
00076 break;
00077 case 1:
00078 mailLink->setLinkName( currentText );
00079 break;
00080 case 2:
00081 fileLink->setLinkName( currentText );
00082 break;
00083 case 3:
00084 {
00085 if ( bookmarkLink)
00086 bookmarkLink->setLinkName( currentText );
00087 }
00088 break;
00089 default:
00090 kdDebug()<<"Error in linkName\n";
00091 }
00092 enableButtonOK( !(linkName().isEmpty() || hrefName().isEmpty()) );
00093 }
00094
00095 void KoInsertLinkDia::slotTextChanged ( )
00096 {
00097 enableButtonOK( !(linkName().isEmpty() || hrefName().isEmpty()));
00098 currentText = linkName();
00099 }
00100
00101 bool KoInsertLinkDia::createLinkDia(QString & _linkName, QString & _hrefName, const QStringList& bkmlist, bool displayBookmarkLink, QWidget* parent, const char* name)
00102 {
00103 bool res = false;
00104
00105 KoInsertLinkDia *dlg = new KoInsertLinkDia( parent, name, displayBookmarkLink );
00106 dlg->setHrefLinkName(_hrefName,_linkName, bkmlist);
00107 if ( dlg->exec() == Accepted )
00108 {
00109 _linkName = dlg->linkName();
00110 _hrefName = dlg->hrefName();
00111 res = true;
00112 }
00113 delete dlg;
00114
00115 return res;
00116 }
00117
00118 void KoInsertLinkDia::setHrefLinkName(const QString &_href, const QString &_link, const QStringList & bkmlist)
00119 {
00120 if ( bookmarkLink)
00121 bookmarkLink->setBookmarkList(bkmlist);
00122 if ( _href.isEmpty())
00123 {
00124 if ( !_link.isEmpty() )
00125 {
00126 internetLink->setLinkName(_link);
00127 showPage(0);
00128 slotTextChanged ( );
00129 }
00130 return;
00131 }
00132 if(_href.find("http://")!=-1 || _href.find("https://")!=-1 ||_href.find("ftp://")!=-1 )
00133 {
00134 internetLink->setHrefName(_href);
00135 internetLink->setLinkName(_link);
00136 showPage(0);
00137 }
00138 else if(_href.find("file:/")!=-1)
00139 {
00140 fileLink->setHrefName(_href);
00141 fileLink->setLinkName(_link);
00142 showPage(2);
00143 }
00144 else if(_href.find("mailto:")!=-1 || _href.find("news:")!=-1)
00145 {
00146 mailLink->setHrefName(_href);
00147 mailLink->setLinkName(_link);
00148 showPage(1);
00149 }
00150 else if(_href.find("bkm://")!=-1)
00151 {
00152 if ( bookmarkLink )
00153 {
00154 bookmarkLink->setHrefName(_href.mid(6));
00155 bookmarkLink->setLinkName(_link);
00156 showPage(3);
00157 }
00158 }
00159 slotTextChanged ( );
00160 }
00161
00162 QString KoInsertLinkDia::linkName() const
00163 {
00164 QString result;
00165 switch(activePageIndex())
00166 {
00167 case 0:
00168 result=internetLink->linkName();
00169 break;
00170 case 1:
00171 result=mailLink->linkName();
00172 break;
00173 case 2:
00174 result=fileLink->linkName();
00175 break;
00176 case 3:
00177 {
00178 if ( bookmarkLink)
00179 result=bookmarkLink->linkName();
00180 }
00181 break;
00182 default:
00183 kdDebug()<<"Error in linkName\n";
00184 }
00185 return result;
00186 }
00187
00188 QString KoInsertLinkDia::hrefName() const
00189 {
00190 QString result;
00191 switch(activePageIndex())
00192 {
00193 case 0:
00194 result=internetLink->hrefName();
00195 break;
00196 case 1:
00197 result=mailLink->hrefName();
00198 break;
00199 case 2:
00200 result=fileLink->hrefName();
00201 break;
00202 case 3:
00203 {
00204 if ( bookmarkLink )
00205 result=bookmarkLink->hrefName();
00206 }
00207 break;
00208 default:
00209 kdDebug()<<"Error in hrefName\n";
00210 }
00211 return result;
00212 }
00213
00214 void KoInsertLinkDia::slotOk()
00215 {
00216 KDialogBase::slotOk();
00217 }
00218
00219
00220 internetLinkPage::internetLinkPage( QWidget *parent , char *name )
00221 : QWidget(parent,name)
00222 {
00223 QVBoxLayout *lay1 = new QVBoxLayout( this );
00224 lay1->setMargin( KDialog::marginHint() );
00225 lay1->setSpacing( KDialog::spacingHint() );
00226 QVBoxLayout *lay2 = new QVBoxLayout( lay1);
00227 lay2->setSpacing( KDialog::spacingHint() );
00228
00229 QLabel* tmpQLabel = new QLabel( this);
00230
00231 lay2->addWidget(tmpQLabel);
00232 tmpQLabel->setText(i18n("Comment:"));
00233
00234 m_linkName = new QLineEdit( this );
00235 lay2->addWidget(m_linkName);
00236
00237 tmpQLabel = new QLabel( this);
00238 lay2->addWidget(tmpQLabel);
00239
00240 tmpQLabel->setText(i18n("Internet address:"));
00241 m_hrefName = new QLineEdit( this );
00242
00243 lay2->addWidget(m_hrefName);
00244
00245 lay2->addStretch( 1 );
00246
00247 m_linkName->setFocus();
00248
00249 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00250 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00251 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this);
00252 bar1->setFixedHeight( 10 );
00253 lay2->addWidget( bar1 );
00254 }
00255
00256 QString internetLinkPage::createInternetLink()
00257 {
00258 QString result=m_hrefName->text();
00259
00260 if(result.isEmpty())
00261 return result;
00262
00263 if(result.find("http://")==-1 && result.find("https://")==-1 && result.find("ftp://")==-1)
00264 result = "http://"+result;
00265 return result;
00266 }
00267
00268
00269 void internetLinkPage::setLinkName(const QString & _name)
00270 {
00271 m_linkName->setText(_name);
00272 }
00273
00274 void internetLinkPage::setHrefName(const QString &_name)
00275 {
00276 m_hrefName->setText(_name);
00277 }
00278
00279 QString internetLinkPage::linkName()const
00280 {
00281 return m_linkName->text();
00282 }
00283
00284 QString internetLinkPage::hrefName()
00285 {
00286 return createInternetLink();
00287 }
00288
00289 void internetLinkPage::textChanged ( const QString & )
00290 {
00291 emit textChanged();
00292 }
00293
00294 bookmarkLinkPage::bookmarkLinkPage( QWidget *parent , char *name )
00295 : QWidget(parent,name)
00296 {
00297 QVBoxLayout *lay1 = new QVBoxLayout( this );
00298 lay1->setMargin( KDialog::marginHint() );
00299 lay1->setSpacing( KDialog::spacingHint() );
00300 QVBoxLayout *lay2 = new QVBoxLayout( lay1);
00301 lay2->setSpacing( KDialog::spacingHint() );
00302
00303 QLabel* tmpQLabel = new QLabel( this);
00304
00305 lay2->addWidget(tmpQLabel);
00306 tmpQLabel->setText(i18n("Comment:"));
00307
00308 m_linkName = new QLineEdit( this );
00309 lay2->addWidget(m_linkName);
00310
00311 tmpQLabel = new QLabel( this);
00312 lay2->addWidget(tmpQLabel);
00313
00314 tmpQLabel->setText(i18n("Bookmark name:"));
00315 m_hrefName = new QComboBox( this );
00316
00317 lay2->addWidget(m_hrefName);
00318
00319 lay2->addStretch( 1 );
00320
00321 m_linkName->setFocus();
00322
00323 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00324 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00325 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this);
00326 bar1->setFixedHeight( 10 );
00327 lay2->addWidget( bar1 );
00328 }
00329
00330 QString bookmarkLinkPage::createBookmarkLink()
00331 {
00332 QString result=m_hrefName->currentText();
00333
00334 if(result.isEmpty())
00335 return result;
00336
00337 if(result.find("bkm://")==-1)
00338 result = "bkm://"+result;
00339 return result;
00340 }
00341
00342
00343 void bookmarkLinkPage::setLinkName(const QString & _name)
00344 {
00345 m_linkName->setText(_name);
00346 }
00347
00348 void bookmarkLinkPage::setHrefName(const QString &_name)
00349 {
00350 m_hrefName->setCurrentText(_name);
00351 }
00352
00353 void bookmarkLinkPage::setBookmarkList(const QStringList & bkmlist)
00354 {
00355 m_hrefName->clear();
00356 m_hrefName->insertStringList(bkmlist, 0);
00357 if ( bkmlist.isEmpty())
00358 m_linkName->setEnabled( false);
00359
00360 }
00361
00362 QString bookmarkLinkPage::linkName()const
00363 {
00364 return m_linkName->text();
00365 }
00366
00367 QString bookmarkLinkPage::hrefName()
00368 {
00369 return createBookmarkLink();
00370 }
00371
00372 void bookmarkLinkPage::textChanged ( const QString & )
00373 {
00374 emit textChanged();
00375 }
00376
00377 mailLinkPage::mailLinkPage( QWidget *parent , char *name )
00378 : QWidget(parent,name)
00379 {
00380 QVBoxLayout *lay1 = new QVBoxLayout( this );
00381 lay1->setMargin( KDialog::marginHint() );
00382 lay1->setSpacing( KDialog::spacingHint() );
00383 QVBoxLayout *lay2 = new QVBoxLayout( lay1);
00384 lay2->setSpacing( KDialog::spacingHint() );
00385
00386 QLabel* tmpQLabel = new QLabel( this);
00387
00388 lay2->addWidget(tmpQLabel);
00389 tmpQLabel->setText(i18n("Comment:"));
00390
00391 m_linkName = new QLineEdit( this );
00392 lay2->addWidget(m_linkName);
00393
00394 tmpQLabel = new QLabel( this);
00395 lay2->addWidget(tmpQLabel);
00396
00397 tmpQLabel->setText(i18n("Target:"));
00398 m_hrefName = new QLineEdit( this );
00399
00400 lay2->addWidget(m_hrefName);
00401 lay2->addStretch( 1 );
00402
00403 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00404 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00405 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this);
00406 bar1->setFixedHeight( 10 );
00407 lay2->addWidget( bar1 );
00408 }
00409
00410 QString mailLinkPage::createMailLink()
00411 {
00412 QString result=m_hrefName->text();
00413
00414 if(result.isEmpty())
00415 return result;
00416
00417 if(result.find("mailto:")==-1 && result.find("news:")==-1)
00418 result = "mailto:"+result;
00419 return result;
00420 }
00421
00422
00423 void mailLinkPage::setLinkName(const QString & _name)
00424 {
00425 m_linkName->setText(_name);
00426 }
00427
00428 void mailLinkPage::setHrefName(const QString &_name)
00429 {
00430 m_hrefName->setText(_name);
00431 }
00432
00433 QString mailLinkPage::linkName()const
00434 {
00435 return m_linkName->text();
00436 }
00437
00438 QString mailLinkPage::hrefName()
00439 {
00440 return createMailLink();
00441 }
00442
00443 void mailLinkPage::textChanged ( const QString & )
00444 {
00445 emit textChanged();
00446 }
00447
00448 fileLinkPage::fileLinkPage( QWidget *parent , char *name )
00449 : QWidget(parent,name)
00450 {
00451 QVBoxLayout *lay1 = new QVBoxLayout( this );
00452 lay1->setMargin( KDialog::marginHint() );
00453 lay1->setSpacing( KDialog::spacingHint() );
00454 QVBoxLayout *lay2 = new QVBoxLayout( lay1);
00455 lay2->setSpacing( KDialog::spacingHint() );
00456
00457 QLabel* tmpQLabel = new QLabel( this);
00458
00459 lay2->addWidget(tmpQLabel);
00460 tmpQLabel->setText(i18n("Comment:"));
00461
00462 m_linkName = new QLineEdit( this );
00463 lay2->addWidget(m_linkName);
00464
00465 tmpQLabel = new QLabel( this);
00466 lay2->addWidget(tmpQLabel);
00467 tmpQLabel->setText(i18n("Recent file:"));
00468
00469 QComboBox * recentFile = new QComboBox( this );
00470 recentFile->setMaximumWidth( kapp->desktop()->width()*3/4 );
00471 lay2->addWidget(recentFile);
00472
00473 QStringList fileList = KRecentDocument::recentDocuments();
00474 QStringList lst;
00475 lst <<"";
00476 for (QStringList::ConstIterator it = fileList.begin();it != fileList.end(); ++it)
00477 {
00478 KDesktopFile f(*it, true );
00479 if ( !f.readURL().isEmpty())
00480 lst.append( f.readURL());
00481 }
00482 if ( lst.count()<= 1 )
00483 {
00484 recentFile->clear();
00485 recentFile->insertItem( i18n("No Entries") );
00486 recentFile->setEnabled( false );
00487 }
00488 else
00489 recentFile->insertStringList( lst);
00490
00491 recentFile->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
00492
00493 connect( recentFile , SIGNAL(highlighted ( const QString &)), this, SLOT( slotSelectRecentFile( const QString & )));
00494
00495 tmpQLabel = new QLabel( this);
00496 lay2->addWidget(tmpQLabel);
00497
00498 tmpQLabel->setText(i18n("File location:"));
00499 m_hrefName = new KURLRequester( this );
00500
00501 lay2->addWidget(m_hrefName);
00502 lay2->addStretch( 1 );
00503
00504 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00505 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & )));
00506
00507 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this);
00508 bar1->setFixedHeight( 10 );
00509 lay2->addWidget( bar1 );
00510 }
00511
00512 void fileLinkPage::slotSelectRecentFile( const QString &_file )
00513 {
00514 m_hrefName->lineEdit()->setText(_file );
00515 }
00516
00517 QString fileLinkPage::createFileLink()
00518 {
00519 QString result=m_hrefName->lineEdit()->text();
00520 if(result.isEmpty())
00521 return result;
00522
00523 if(result.find("file:/")==-1)
00524 result = "file:/"+result;
00525 return result;
00526 }
00527
00528 void fileLinkPage::setLinkName(const QString & _name)
00529 {
00530 m_linkName->setText(_name);
00531 }
00532
00533 void fileLinkPage::setHrefName(const QString &_name)
00534 {
00535 m_hrefName->lineEdit()->setText(_name);
00536 }
00537
00538 QString fileLinkPage::linkName()const
00539 {
00540 return m_linkName->text();
00541 }
00542
00543 QString fileLinkPage::hrefName()
00544 {
00545 return createFileLink();
00546 }
00547
00548 void fileLinkPage::textChanged ( const QString & )
00549 {
00550 emit textChanged();
00551 }
00552
00553 #include "koInsertLink.moc"