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