lib Library API Documentation

koInsertLink.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Montel Laurent <lmontel@mandrakesoft.com> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <klocale.h> 00021 00022 #include <qlayout.h> 00023 #include <qvbox.h> 00024 #include <kdebug.h> 00025 #include <qlabel.h> 00026 #include <qcombobox.h> 00027 00028 #include <klineedit.h> 00029 #include <kurlrequester.h> 00030 #include <kseparator.h> 00031 #include <kiconloader.h> 00032 #include "koInsertLink.h" 00033 #include <kdesktopfile.h> 00034 #include <krecentdocument.h> 00035 00036 00037 KoInsertLinkDia::KoInsertLinkDia( QWidget */*parent*/, const char */*name*/,bool displayBookmarkLink ) 00038 : KDialogBase( KDialogBase::IconList, i18n("Insert Link"), 00039 KDialogBase::Ok | KDialogBase::Cancel, 00040 KDialogBase::Ok) 00041 { 00042 bookmarkLink = 0L; 00043 QVBox *page=addVBoxPage(i18n("Internet"), QString::null,BarIcon("html",KIcon::SizeMedium)); 00044 internetLink = new internetLinkPage(page ); 00045 connect(internetLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ( ))); 00046 00047 page=addVBoxPage(i18n("Mail & News"), QString::null,BarIcon("mail_generic",KIcon::SizeMedium)); 00048 mailLink = new mailLinkPage(page ); 00049 connect(mailLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ())); 00050 00051 page=addVBoxPage(i18n("File"), QString::null,BarIcon("filenew",KIcon::SizeMedium)); 00052 fileLink = new fileLinkPage(page ); 00053 connect(fileLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ())); 00054 00055 if ( displayBookmarkLink) 00056 { 00057 page=addVBoxPage(i18n("Bookmark"), QString::null,BarIcon("bookmark",KIcon::SizeMedium)); 00058 bookmarkLink = new bookmarkLinkPage(page ); 00059 connect(bookmarkLink,SIGNAL(textChanged()),this,SLOT(slotTextChanged ())); 00060 } 00061 00062 slotTextChanged ( ); 00063 resize(400,300); 00064 } 00065 00066 00067 void KoInsertLinkDia::slotTextChanged ( ) 00068 { 00069 enableButtonOK( !(linkName().isEmpty() || hrefName().isEmpty())); 00070 } 00071 00072 bool KoInsertLinkDia::createLinkDia(QString & _linkName, QString & _hrefName, QStringList bkmlist, bool displayBookmarkLink) 00073 { 00074 bool res = false; 00075 00076 KoInsertLinkDia *dlg = new KoInsertLinkDia( 0L, "Insert Link", displayBookmarkLink ); 00077 dlg->setHrefLinkName(_hrefName,_linkName, bkmlist); 00078 if ( dlg->exec() == Accepted ) 00079 { 00080 _linkName = dlg->linkName(); 00081 _hrefName = dlg->hrefName(); 00082 res = true; 00083 } 00084 delete dlg; 00085 00086 return res; 00087 } 00088 00089 void KoInsertLinkDia::setHrefLinkName(const QString &_href, const QString &_link, const QStringList & bkmlist) 00090 { 00091 if ( bookmarkLink) 00092 bookmarkLink->setBookmarkList(bkmlist); 00093 if( _href.isEmpty()) 00094 return; 00095 if(_href.find("http://")!=-1 || _href.find("https://")!=-1 ||_href.find("ftp://")!=-1 ) 00096 { 00097 internetLink->setHrefName(_href); 00098 internetLink->setLinkName(_link); 00099 showPage(0); 00100 } 00101 else if(_href.find("file:/")!=-1) 00102 { 00103 fileLink->setHrefName(_href); 00104 fileLink->setLinkName(_link); 00105 showPage(2); 00106 } 00107 else if(_href.find("mailto:")!=-1 || _href.find("news:")!=-1) 00108 { 00109 mailLink->setHrefName(_href); 00110 mailLink->setLinkName(_link); 00111 showPage(1); 00112 } 00113 else if(_href.find("bkm://")!=-1) 00114 { 00115 if ( bookmarkLink ) 00116 { 00117 bookmarkLink->setHrefName(_href.mid(6)); 00118 bookmarkLink->setLinkName(_link); 00119 showPage(3); 00120 } 00121 } 00122 slotTextChanged ( ); 00123 } 00124 00125 QString KoInsertLinkDia::linkName()const 00126 { 00127 QString result; 00128 switch(activePageIndex()) 00129 { 00130 case 0: 00131 result=internetLink->linkName(); 00132 break; 00133 case 1: 00134 result=mailLink->linkName(); 00135 break; 00136 case 2: 00137 result=fileLink->linkName(); 00138 break; 00139 case 3: 00140 { 00141 if ( bookmarkLink) 00142 result=bookmarkLink->linkName(); 00143 } 00144 break; 00145 default: 00146 kdDebug()<<"Error in linkName\n"; 00147 } 00148 return result; 00149 } 00150 00151 QString KoInsertLinkDia::hrefName() 00152 { 00153 QString result; 00154 switch(activePageIndex()) 00155 { 00156 case 0: 00157 result=internetLink->hrefName(); 00158 break; 00159 case 1: 00160 result=mailLink->hrefName(); 00161 break; 00162 case 2: 00163 result=fileLink->hrefName(); 00164 break; 00165 case 3: 00166 { 00167 if ( bookmarkLink ) 00168 result=bookmarkLink->hrefName(); 00169 } 00170 break; 00171 default: 00172 kdDebug()<<"Error in hrefName\n"; 00173 } 00174 return result; 00175 } 00176 00177 void KoInsertLinkDia::slotOk() 00178 { 00179 KDialogBase::slotOk(); 00180 } 00181 00182 00183 internetLinkPage::internetLinkPage( QWidget *parent , char *name ) 00184 : QWidget(parent,name) 00185 { 00186 QVBoxLayout *lay1 = new QVBoxLayout( this ); 00187 lay1->setMargin( KDialog::marginHint() ); 00188 lay1->setSpacing( KDialog::spacingHint() ); 00189 QVBoxLayout *lay2 = new QVBoxLayout( lay1); 00190 lay2->setSpacing( KDialog::spacingHint() ); 00191 00192 QLabel* tmpQLabel = new QLabel( this); 00193 00194 lay2->addWidget(tmpQLabel); 00195 tmpQLabel->setText(i18n("Comment:")); 00196 00197 m_linkName = new QLineEdit( this ); 00198 lay2->addWidget(m_linkName); 00199 00200 tmpQLabel = new QLabel( this); 00201 lay2->addWidget(tmpQLabel); 00202 00203 tmpQLabel->setText(i18n("Internet address:")); 00204 m_hrefName = new QLineEdit( this ); 00205 00206 lay2->addWidget(m_hrefName); 00207 00208 m_linkName->setFocus(); 00209 00210 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00211 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00212 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this); 00213 bar1->setFixedHeight( 10 ); 00214 lay2->addWidget( bar1 ); 00215 } 00216 00217 QString internetLinkPage::createInternetLink() 00218 { 00219 QString result=m_hrefName->text(); 00220 00221 if(result.isEmpty()) 00222 return result; 00223 00224 if(result.find("http://")==-1 && result.find("https://")==-1 && result.find("ftp://")==-1) 00225 result = "http://"+result; 00226 return result; 00227 } 00228 00229 00230 void internetLinkPage::setLinkName(const QString & _name) 00231 { 00232 m_linkName->setText(_name); 00233 } 00234 00235 void internetLinkPage::setHrefName(const QString &_name) 00236 { 00237 m_hrefName->setText(_name); 00238 } 00239 00240 QString internetLinkPage::linkName()const 00241 { 00242 return m_linkName->text(); 00243 } 00244 00245 QString internetLinkPage::hrefName() 00246 { 00247 return createInternetLink(); 00248 } 00249 00250 void internetLinkPage::textChanged ( const QString & ) 00251 { 00252 emit textChanged(); 00253 } 00254 00255 bookmarkLinkPage::bookmarkLinkPage( QWidget *parent , char *name ) 00256 : QWidget(parent,name) 00257 { 00258 QVBoxLayout *lay1 = new QVBoxLayout( this ); 00259 lay1->setMargin( KDialog::marginHint() ); 00260 lay1->setSpacing( KDialog::spacingHint() ); 00261 QVBoxLayout *lay2 = new QVBoxLayout( lay1); 00262 lay2->setSpacing( KDialog::spacingHint() ); 00263 00264 QLabel* tmpQLabel = new QLabel( this); 00265 00266 lay2->addWidget(tmpQLabel); 00267 tmpQLabel->setText(i18n("Comment:")); 00268 00269 m_linkName = new QLineEdit( this ); 00270 lay2->addWidget(m_linkName); 00271 00272 tmpQLabel = new QLabel( this); 00273 lay2->addWidget(tmpQLabel); 00274 00275 tmpQLabel->setText(i18n("Bookmark name:")); 00276 m_hrefName = new QComboBox( this ); 00277 00278 lay2->addWidget(m_hrefName); 00279 00280 m_linkName->setFocus(); 00281 00282 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00283 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00284 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this); 00285 bar1->setFixedHeight( 10 ); 00286 lay2->addWidget( bar1 ); 00287 } 00288 00289 QString bookmarkLinkPage::createBookmarkLink() 00290 { 00291 QString result=m_hrefName->currentText(); 00292 00293 if(result.isEmpty()) 00294 return result; 00295 00296 if(result.find("bkm://")==-1) 00297 result = "bkm://"+result; 00298 return result; 00299 } 00300 00301 00302 void bookmarkLinkPage::setLinkName(const QString & _name) 00303 { 00304 m_linkName->setText(_name); 00305 } 00306 00307 void bookmarkLinkPage::setHrefName(const QString &_name) 00308 { 00309 m_hrefName->setCurrentText(_name); 00310 } 00311 00312 void bookmarkLinkPage::setBookmarkList(const QStringList & bkmlist) 00313 { 00314 m_hrefName->clear(); 00315 m_hrefName->insertStringList(bkmlist, 0); 00316 if ( bkmlist.isEmpty()) 00317 m_linkName->setEnabled( false); 00318 //m_hrefName->setEditable(true); 00319 } 00320 00321 QString bookmarkLinkPage::linkName()const 00322 { 00323 return m_linkName->text(); 00324 } 00325 00326 QString bookmarkLinkPage::hrefName() 00327 { 00328 return createBookmarkLink(); 00329 } 00330 00331 void bookmarkLinkPage::textChanged ( const QString & ) 00332 { 00333 emit textChanged(); 00334 } 00335 00336 mailLinkPage::mailLinkPage( QWidget *parent , char *name ) 00337 : QWidget(parent,name) 00338 { 00339 QVBoxLayout *lay1 = new QVBoxLayout( this ); 00340 lay1->setMargin( KDialog::marginHint() ); 00341 lay1->setSpacing( KDialog::spacingHint() ); 00342 QVBoxLayout *lay2 = new QVBoxLayout( lay1); 00343 lay2->setSpacing( KDialog::spacingHint() ); 00344 00345 QLabel* tmpQLabel = new QLabel( this); 00346 00347 lay2->addWidget(tmpQLabel); 00348 tmpQLabel->setText(i18n("Comment:")); 00349 00350 m_linkName = new QLineEdit( this ); 00351 lay2->addWidget(m_linkName); 00352 00353 tmpQLabel = new QLabel( this); 00354 lay2->addWidget(tmpQLabel); 00355 00356 tmpQLabel->setText(i18n("Target:")); 00357 m_hrefName = new QLineEdit( this ); 00358 00359 lay2->addWidget(m_hrefName); 00360 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00361 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00362 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this); 00363 bar1->setFixedHeight( 10 ); 00364 lay2->addWidget( bar1 ); 00365 } 00366 00367 QString mailLinkPage::createMailLink() 00368 { 00369 QString result=m_hrefName->text(); 00370 00371 if(result.isEmpty()) 00372 return result; 00373 00374 if(result.find("mailto:")==-1 && result.find("news:")==-1) 00375 result = "mailto:"+result; 00376 return result; 00377 } 00378 00379 00380 void mailLinkPage::setLinkName(const QString & _name) 00381 { 00382 m_linkName->setText(_name); 00383 } 00384 00385 void mailLinkPage::setHrefName(const QString &_name) 00386 { 00387 m_hrefName->setText(_name); 00388 } 00389 00390 QString mailLinkPage::linkName()const 00391 { 00392 return m_linkName->text(); 00393 } 00394 00395 QString mailLinkPage::hrefName() 00396 { 00397 return createMailLink(); 00398 } 00399 00400 void mailLinkPage::textChanged ( const QString & ) 00401 { 00402 emit textChanged(); 00403 } 00404 00405 fileLinkPage::fileLinkPage( QWidget *parent , char *name ) 00406 : QWidget(parent,name) 00407 { 00408 QVBoxLayout *lay1 = new QVBoxLayout( this ); 00409 lay1->setMargin( KDialog::marginHint() ); 00410 lay1->setSpacing( KDialog::spacingHint() ); 00411 QVBoxLayout *lay2 = new QVBoxLayout( lay1); 00412 lay2->setSpacing( KDialog::spacingHint() ); 00413 00414 QLabel* tmpQLabel = new QLabel( this); 00415 00416 lay2->addWidget(tmpQLabel); 00417 tmpQLabel->setText(i18n("Comment:")); 00418 00419 m_linkName = new QLineEdit( this ); 00420 lay2->addWidget(m_linkName); 00421 00422 tmpQLabel = new QLabel( this); 00423 lay2->addWidget(tmpQLabel); 00424 tmpQLabel->setText(i18n("Recent file:")); 00425 00426 00427 QComboBox * recentFile = new QComboBox( this ); 00428 lay2->addWidget(recentFile); 00429 00430 QStringList fileList = KRecentDocument::recentDocuments(); 00431 QStringList lst; 00432 lst <<""; 00433 for (QStringList::ConstIterator it = fileList.begin();it != fileList.end(); ++it) 00434 { 00435 KDesktopFile f(*it, true /* read only */); 00436 if ( !f.readURL().isEmpty()) 00437 lst.append( f.readURL()); 00438 } 00439 if ( lst.count()<= 1 ) 00440 { 00441 recentFile->clear(); 00442 recentFile->insertItem( i18n("No Entries") ); 00443 recentFile->setEnabled( false ); 00444 } 00445 else 00446 recentFile->insertStringList( lst); 00447 connect( recentFile , SIGNAL(highlighted ( const QString &)), this, SLOT( slotSelectRecentFile( const QString & ))); 00448 00449 tmpQLabel = new QLabel( this); 00450 lay2->addWidget(tmpQLabel); 00451 00452 tmpQLabel->setText(i18n("File location:")); 00453 m_hrefName = new KURLRequester( this ); 00454 00455 lay2->addWidget(m_hrefName); 00456 00457 connect(m_linkName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00458 connect(m_hrefName,SIGNAL(textChanged ( const QString & )),this,SLOT(textChanged ( const QString & ))); 00459 00460 KSeparator* bar1 = new KSeparator( KSeparator::HLine, this); 00461 bar1->setFixedHeight( 10 ); 00462 lay2->addWidget( bar1 ); 00463 } 00464 00465 void fileLinkPage::slotSelectRecentFile( const QString &_file ) 00466 { 00467 m_hrefName->lineEdit()->setText(_file ); 00468 } 00469 00470 QString fileLinkPage::createFileLink() 00471 { 00472 QString result=m_hrefName->lineEdit()->text(); 00473 if(result.isEmpty()) 00474 return result; 00475 00476 if(result.find("file:/")==-1) 00477 result = "file:/"+result; 00478 return result; 00479 } 00480 00481 void fileLinkPage::setLinkName(const QString & _name) 00482 { 00483 m_linkName->setText(_name); 00484 } 00485 00486 void fileLinkPage::setHrefName(const QString &_name) 00487 { 00488 m_hrefName->lineEdit()->setText(_name); 00489 } 00490 00491 QString fileLinkPage::linkName()const 00492 { 00493 return m_linkName->text(); 00494 } 00495 00496 QString fileLinkPage::hrefName() 00497 { 00498 return createFileLink(); 00499 } 00500 00501 void fileLinkPage::textChanged ( const QString & ) 00502 { 00503 emit textChanged(); 00504 } 00505 00506 #include "koInsertLink.moc"
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 06:54:16 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003