KDevelop API Documentation

parts/doctreeview/adddocitemdlg.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 1999 by Sandy Meier * 00003 * smeier@kdevelop.org * 00004 * Copyright (C) 2003 by Alexander Dymo * 00005 * cloudtemple@mksat.net * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 ***************************************************************************/ 00013 00014 #include "adddocitemdlg.h" 00015 #include "misc.h" 00016 00017 #include <qlabel.h> 00018 #include <qlayout.h> 00019 #include <qpushbutton.h> 00020 #include <qwhatsthis.h> 00021 #include <qdom.h> 00022 #include <kbuttonbox.h> 00023 #include <kfiledialog.h> 00024 #include <klocale.h> 00025 #include <kstdguiitem.h> 00026 #include <klineedit.h> 00027 00028 AddDocItemDialog::AddDocItemDialog(KFile::Mode mode, QString filter, TitleType checkDocTitle, QString title, QString url, QWidget *parent, const char *name) 00029 : QDialog(parent, name, true), m_mode(mode), m_type(checkDocTitle), m_filter(filter) 00030 { 00031 setCaption(i18n("Add Documentation Entry")); 00032 00033 title_check = 0; 00034 if (m_type == Qt) 00035 title_check = new QCheckBox(i18n("Custom title"), this); 00036 00037 QLabel *title_label = new QLabel(i18n("&Title:"), this); 00038 title_edit = new QLineEdit(this); 00039 title_edit->setText(title); 00040 title_edit->setFocus(); 00041 title_label->setBuddy(title_edit); 00042 00043 QLabel *url_label = new QLabel(i18n("&Location:"), this); 00044 url_edit = new KURLRequester(this); 00045 url_label->setBuddy(url_edit); 00046 QFontMetrics fm(url_edit->fontMetrics()); 00047 url_edit->setURL(url); 00048 url_edit->setMinimumWidth(fm.width('X')*35); 00049 url_edit->setFilter(m_filter); 00050 url_edit->setMode((int) m_mode); 00051 00052 /* QPushButton *url_button = new QPushButton("...", this); 00053 url_button->setFixedSize(30, 25); 00054 00055 connect( url_button, SIGNAL(clicked()), this, SLOT(fileButtonClicked())); 00056 */ 00057 QString s = i18n("Enter the name of the entry here."); 00058 QWhatsThis::add(title_label, s); 00059 QWhatsThis::add(title_edit, s); 00060 s = i18n("Enter the location of the entry here."); 00061 QWhatsThis::add(url_label, s); 00062 QWhatsThis::add(url_edit, s); 00063 /* s = i18n("Here you can browse through your file system to select a location for the entry."); 00064 QWhatsThis::add(url_button, s);*/ 00065 00066 QVBoxLayout *layout = new QVBoxLayout(this, 10); 00067 00068 QGridLayout *grid = new QGridLayout(2, 3); 00069 if (m_type == Qt) 00070 { 00071 layout->addWidget(title_check); 00072 } 00073 layout->addLayout(grid); 00074 grid->addWidget(title_label, 0, 0); 00075 grid->addMultiCellWidget(title_edit, 0, 0, 1, 2); 00076 grid->addWidget(url_label, 1, 0); 00077 grid->addWidget(url_edit, 1, 1); 00078 // grid->addWidget(url_button, 1, 2); 00079 00080 QFrame *frame = new QFrame(this); 00081 frame->setFrameStyle(QFrame::HLine | QFrame::Sunken); 00082 layout->addWidget(frame, 0); 00083 00084 KButtonBox *buttonbox = new KButtonBox(this); 00085 buttonbox->addStretch(); 00086 m_pOk = buttonbox->addButton(KStdGuiItem::ok().text()); 00087 QPushButton *cancel = buttonbox->addButton(KStdGuiItem::cancel().text()); 00088 m_pOk->setDefault(true); 00089 connect( m_pOk, SIGNAL(clicked()), this, SLOT(accept()) ); 00090 connect( cancel, SIGNAL(clicked()), this, SLOT(reject()) ); 00091 buttonbox->layout(); 00092 layout->addWidget(buttonbox, 0); 00093 00094 if (m_type != None) 00095 { 00096 title_edit->setEnabled(false); 00097 if (m_type == Qt) 00098 connect(title_check, SIGNAL(toggled(bool)), title_edit, SLOT(setEnabled(bool))); 00099 connect(url_edit, SIGNAL(textChanged(const QString&)), this, SLOT(setTitle(const QString&))); 00100 } 00101 connect( url_edit, SIGNAL(textChanged(const QString&)), this, SLOT(setLocationChanged(const QString&))); 00102 setLocationChanged(url_edit->lineEdit()->text() ); 00103 } 00104 00105 00106 AddDocItemDialog::~AddDocItemDialog() 00107 {} 00108 00109 void AddDocItemDialog::setLocationChanged(const QString & _text ) 00110 { 00111 m_pOk->setEnabled( !_text.isEmpty() ); 00112 } 00113 00114 void AddDocItemDialog::setTitle(const QString &str) 00115 { 00116 if ( m_type == Qt) 00117 { 00118 if (title_check->isChecked()) 00119 return; 00120 title_edit->setText(""); 00121 QFileInfo fi(str); 00122 if (!fi.exists()) 00123 return; 00124 00125 QFile f(str); 00126 if (!f.open(IO_ReadOnly)) { 00127 return; 00128 } 00129 QDomDocument doc; 00130 if (!doc.setContent(&f) || doc.doctype().name() != "DCF") { 00131 return; 00132 } 00133 f.close(); 00134 00135 QDomElement docEl = doc.documentElement(); 00136 00137 title_edit->setText(docEl.attribute("title", QString::null)); 00138 } 00139 else if (m_type == DevHelp) 00140 { 00141 title_edit->setText(""); 00142 QFileInfo fi(str); 00143 if (!fi.exists()) 00144 return; 00145 00146 QFile f(str); 00147 if (!f.open(IO_ReadOnly)) { 00148 return; 00149 } 00150 QDomDocument doc; 00151 if (!doc.setContent(&f)) { 00152 return; 00153 } 00154 f.close(); 00155 00156 QDomElement docEl = doc.documentElement(); 00157 00158 title_edit->setText(docEl.attribute("title", QString::null)); 00159 } 00160 else if (m_type == KDevelopTOC) 00161 { 00162 title_edit->setText(DocTreeViewTool::tocTitle(str)); 00163 } 00164 } 00165 00166 #include "adddocitemdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:10 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003