File indexing completed on 2024-04-28 04:02:31
0001 /*************************************************************************** 0002 dlgdumpbuffer.cpp - Dump Buffer dialog 0003 ------------------- 0004 begin : Pi feb 28 2003 0005 copyright : (C) 2003 by Tomas Mecir 0006 email : kmuddy@kmuddy.com 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 ***************************************************************************/ 0017 0018 #include "dlgdumpbuffer.h" 0019 0020 #include "cconsole.h" 0021 0022 #include <qcheckbox.h> 0023 #include <qcombobox.h> 0024 #include <QFileDialog> 0025 #include <QDialogButtonBox> 0026 #include <qlabel.h> 0027 #include <qpushbutton.h> 0028 #include <QHBoxLayout> 0029 #include <QVBoxLayout> 0030 #include <QFrame> 0031 #include <QLineEdit> 0032 0033 #include <KLocalizedString> 0034 0035 dlgDumpBuffer::dlgDumpBuffer (QWidget *parent) : QDialog (parent) 0036 { 0037 //initial dialog size 0038 setWindowTitle (i18n ("Dump output buffer")); 0039 0040 //create main dialog's widget 0041 QVBoxLayout *layout = new QVBoxLayout (this); 0042 0043 //where to start? 0044 chkcurpos = new QCheckBox (i18n ("&Start at current position"), this); 0045 chkcurpos->setWhatsThis( i18n ("When this is enabled, only the " 0046 "part of history buffer from currently displayed part up to the end of " 0047 "buffer will be dumped. Otherwise entire buffer will be dumped (default).")); 0048 0049 //the file name 0050 QFrame *fileframe = new QFrame (this); 0051 QHBoxLayout *filelayout = new QHBoxLayout (fileframe); 0052 QLabel *lblname = new QLabel (i18n ("&File:"), fileframe); 0053 fname = new QLineEdit (fileframe); 0054 lblname->setBuddy (fname); 0055 QPushButton *filebutton = new QPushButton (i18n ("&Browse..."), fileframe); 0056 0057 filelayout->setSpacing (5); 0058 filelayout->addWidget (lblname); 0059 filelayout->addWidget (fname); 0060 filelayout->addWidget (filebutton); 0061 0062 //type 0063 QFrame *typeframe = new QFrame (this); 0064 QHBoxLayout *typelayout = new QHBoxLayout (typeframe); 0065 QLabel *lbltype = new QLabel (i18n ("&Dump format:"), typeframe); 0066 ttype = new QComboBox (typeframe); 0067 ttype->addItem (i18n ("HTML")); 0068 ttype->addItem (i18n ("Plain text")); 0069 ttype->addItem (i18n ("Text with ANSI colors")); 0070 lbltype->setBuddy (ttype); 0071 0072 typelayout->setSpacing (5); 0073 typelayout->addWidget (lbltype); 0074 typelayout->addWidget (ttype); 0075 0076 QDialogButtonBox *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0077 connect (buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); 0078 connect (buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); 0079 0080 connect (filebutton, &QPushButton::clicked, this, &dlgDumpBuffer::browseFiles); 0081 connect (ttype, QOverload<int>::of(&QComboBox::activated), this, &dlgDumpBuffer::updateFname); 0082 0083 layout->setSpacing (5); 0084 layout->addWidget (chkcurpos); 0085 layout->addWidget (fileframe); 0086 layout->addWidget (typeframe); 0087 layout->addWidget (buttons); 0088 0089 //initial dialog settings... 0090 chkcurpos->setChecked (false); 0091 fname->setText (QDir::homePath() + "/buffer_dump.html"); 0092 } 0093 0094 dlgDumpBuffer::~dlgDumpBuffer () 0095 { 0096 0097 } 0098 0099 QSize dlgDumpBuffer::sizeHint() const 0100 { 0101 return QSize (300, 100); 0102 } 0103 0104 void dlgDumpBuffer::browseFiles () 0105 { 0106 fname->setText (QFileDialog::getSaveFileName ()); 0107 } 0108 0109 bool dlgDumpBuffer::curPos () 0110 { 0111 return chkcurpos->isChecked (); 0112 } 0113 0114 QString dlgDumpBuffer::fileName () 0115 { 0116 return fname->text (); 0117 } 0118 0119 void dlgDumpBuffer::setFileName (const QString &fName) 0120 { 0121 fname->setText (fName); 0122 } 0123 0124 void dlgDumpBuffer::updateFname (int option) 0125 { 0126 //If we set it to html... 0127 //and we don't end with a .txt and a .html? 0128 //add a .html 0129 //or we dont end with a .html, but with a .txt? 0130 //replace .txt with .html 0131 //or we want it to end with a .txt? Same thing again.. 0132 0133 QString tempString = fname->text(); 0134 bool hasHtml = tempString.endsWith (".html", Qt::CaseInsensitive); 0135 bool hasTxt = tempString.endsWith (".txt", Qt::CaseInsensitive); 0136 if (option + 1 == TRANSCRIPT_HTML) 0137 { 0138 if (hasHtml) return; // we already have the right suffix 0139 if (hasTxt) tempString.remove (tempString.length() - 4, 4); 0140 tempString.append(".html"); 0141 } else { 0142 if (hasTxt) return; // we already have the right suffix 0143 if (hasHtml) tempString.remove (tempString.length() - 5, 5); 0144 tempString.append(".txt"); 0145 } 0146 0147 fname->setText(tempString); 0148 } 0149 0150 0151 int dlgDumpBuffer::type () 0152 { 0153 return ttype->currentIndex() + 1; 0154 } 0155 0156 void dlgDumpBuffer::setType (int t) 0157 { 0158 ttype->setCurrentIndex (t - 1); 0159 } 0160 0161 #include "moc_dlgdumpbuffer.cpp"