/*! *\~english * Writes text to log. *\~russian * Пишет текст в лог. *\~ * \param log_name - \~english Full path to logfile \~russian Полный путь к лог файлу \~ * \param test_name - \~english Test name \~russian Имя теста \~ * \param status - \~english OK, ERROR or SKIP \~russian OK, ОШИБКА или ПРОПУЩЕН \~ * \param text - \~english Comment \~russian Комментарий \~ */ void aTests::print2log( const QString &log_name, const QString &test_name, const QString &status, const QString &text) { QString toWrite = QString("%1::%2::%3::%4\r\n")\ .arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace('T',' '))\ .arg(test_name)\ .arg(status)\ .arg(text); QFile f; if(log_name==QString::null) { f.open( QIODevice::WriteOnly, stdout ); f.writeBlock((const char*)toWrite,strlen((const char*)toWrite)); } else { f.setName(log_name); f.open( QIODevice::WriteOnly | QIODevice::Append ); f.writeBlock((const char*)toWrite,strlen((const char*)toWrite)); f.flush(); } f.close(); // else printf("error write to log\n"); }
void Joystick::saveToFile(QFile &file) { QString s; QString t; // Comment line s = QString("# Input device entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Joystick") + QString("\n"); file.writeBlock((const char*) s, s.length()); // File descriptor s = QString("FDName = ") + fdName() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Axis invert status for (unsigned int i = 0; i < m_axesList.count(); i++) { if (m_axesList.at(i)->invert == true) t = QString("true"); else t = QString("false"); s = QString("AxisInvert = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } }
void Chaser::saveToFile(QFile &file) { QString s; QString t; // Comment line s = QString("# Function entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Function") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Type s = QString("Type = ") + typeString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Device class, device name or "Global" if (deviceClass() != NULL) { // For device class chasers we need to save only the steps because // all scenes are inside the device class for (ChaserStep* step = m_steps.first(); step != NULL; step = m_steps.next()) { s = QString("Function = ") + step->feederFunction->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); } } else if (device() != NULL) { // For device chasers (that are saved in the workspace file) // write also the device name that this chaser is attached to s = QString("Device = ") + device()->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); for (ChaserStep* step = m_steps.first(); step != NULL; step = m_steps.next()) { s = QString("Function = ") + step->feederFunction->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); } } else { // For global chasers, write device+scene pairs for (ChaserStep* step = m_steps.first(); step != NULL; step = m_steps.next()) { // Global chasers need a device+scene pair s = QString("Device = ") + step->callerDevice->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); s = QString("Function = ") + step->feederFunction->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); } } }
void ZGui::saveAs ( const QString fileName, bool save ) { if ( (access(fileName.utf8(),0) == 0) && !save ) { QString sBody = lng->getString("REWRITE").arg ( getFileName(fileName) ); ZMessageDlg * pConfirmation = new ZMessageDlg ( lng->getString("SAVING"), sBody, ( ZMessageDlg::MessageDlgType )1, 0, this, "2", true, 0 ); if ( pConfirmation->exec() ) { ZMessageDlg * pMessage = new ZMessageDlg ( lng->getString("SAVING"), lng->getString("CHANGED"), ( ZMessageDlg::MessageDlgType )1, 0, this, "saveas", true, 0 ); pMessage->show(); delete pMessage; } delete pConfirmation; } if ( !(access(getFilePath(fileName).utf8(),02) == 0) ) // Check save to ReadOnly FS { ZMessageDlg * pWarning = new ZMessageDlg ( lng->getString("ERROR"), "Do not save to ReadOnly FS!", ( ZMessageDlg::MessageDlgType )2, 0, this, "saveas", true, 0 ); pWarning->exec(); delete pWarning; return; } if ( access(fileName.utf8(),0) == 0 ) //remove file for rewrite remove(fileName.utf8()); QFile file ( fileName ); if ( !file.open ( IO_WriteOnly | IO_Truncate ) ) { ZMessageDlg * pWarning = new ZMessageDlg ( lng->getString("ERROR"), lng->getString("FILE_SAVING_FAILED"), ( ZMessageDlg::MessageDlgType )2, 0, this, "saveas", true, 0 ); pWarning->exec(); delete pWarning; return; } QTextCodec* codec = codecByLocalId(textCode); file.reset(); QCString str = codec->fromUnicode( edit->text() ); file.writeBlock( str, str.length() ); char endFile[]={0}; file.writeBlock( endFile, sizeof(endFile) ); file.flush(); file.close(); ZMessageDlg * pMessage = new ZMessageDlg ( lng->getString("SAVING"), lng->getString("FILE_SAVING_SUCCESS"), ( ZMessageDlg::MessageDlgType ) 2, 0, this, "saveas", true, 0 ); pMessage->exec(); delete pMessage; }
void Scene::saveToFile(QFile &file) { QString s; QString t; // Comment line s = QString("# Function entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Function") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Type s = QString("Type = ") + typeString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Device class, device name or "Global" if (deviceClass() != NULL) { // Write only the data for device class scenes for (unsigned i = 1; i < deviceClass()->m_channels.count(); i++) { t.setNum(i); s = t + QString(" = "); t.setNum(m_values[i]); s += t + QString("\n"); file.writeBlock((const char*) s, s.length()); } } else if (device() != NULL) { // For device scenes (that are saved in the workspace file) // write also the device name that this scene is attached to s = QString("Device = ") + device()->name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Data for (unsigned i = 1; i < device()->deviceClass()->m_channels.count(); i++) { t.setNum(i); s = t + QString(" = "); t.setNum(m_values[i]); s += t + QString("\n"); file.writeBlock((const char*) s, s.length()); } } else { // For global scenes the device name is "Global" s = QString("Device = Global") + QString("\n"); file.writeBlock((const char*) s, s.length()); } }
QString copyfile(const QString &filename) { kdDebug(500) << "Copying file " << filename << endl; QString result; QFile f(filename); if(f.open(IO_ReadOnly)) { KTempFile temp; temp.setAutoDelete(false); QFile *tf = temp.file(); if(tf) { char buffer[0xFFFF]; int b = 0; while((b = f.readBlock(buffer, 0xFFFF)) > 0) { if(tf->writeBlock(buffer, b) != b) break; } tf->close(); if(b > 0) temp.setAutoDelete(true); else { kdDebug(500) << "File copied to " << temp.name() << endl; result = temp.name(); } } else temp.setAutoDelete(true); f.close(); } return result; }
void Chaser::saveToFile(QFile &file) { QString s; QString t; // Comment line s = QString("# Function entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Function") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Type s = QString("Type = ") + typeString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // ID s.sprintf("ID = %ld\n", m_id); file.writeBlock((const char*) s, s.length()); // Device if (m_device != NULL) { t.setNum(m_device->id()); s = QString("Device = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } else { s = QString("Device = 0\n"); file.writeBlock((const char*) s, s.length()); } // Steps s = QString("# Step entries") + QString("\n"); file.writeBlock((const char*) s, s.length()); for (ChaserStep* step = m_steps.first(); step != NULL; step = m_steps.next()) { ASSERT(step->function() != NULL); s.sprintf("Function = %ld\n", step->function()->id()); file.writeBlock((const char*) s, s.length()); } }
int initDaemon() { pid_t pid; QString s; QString pidFileName; QFile pidFile; // we probably have a nice little race condition here that I am not // going to worry about right now. s.sprintf("%s/share/apps/korganizer",KApplication::localkdedir().data()); qd.setPath(s.data()); pidFileName.sprintf("%s/alarmd.pid",s.data()); pidFile.setName(pidFileName.data()); // a lock file already exists, don't start up. if (pidFile.exists()) { if(pidFile.open(IO_ReadOnly)) { pid_t pid; char pidStr[25]; pidFile.readLine(pidStr, 24); pidFile.close(); pid = atoi(pidStr); if (kill(pid, SIGUSR1) < 0) { // stale lockfile unlink(pidFileName.data()); // get rid of old lockfile } } } // if the PID file still exists, a daemon really is running. // quit silently. if (pidFile.exists()) { exit(0); } else { // make ourselves a daemon if ((pid = fork()) < 0) return(-1); // we had an error forking else if (pid != 0) { // make a lock file. pidFile.open(IO_ReadWrite); s.sprintf("%d",pid); pidFile.writeBlock(s.data(), s.length()); pidFile.close(); exit(0); // parent dies silently } // child continues setsid(); if (getenv("$HOME") != NULL) chdir(getenv("$HOME")); umask(0); } return(0); }
/*! *\~english * Writes line in log with name \a log_name *\~russian * Пишет строку в лог с именем \a log_name *\~ * \param log_name - \~english logfile name \~russian Путь к логу (не обязательно) \~ */ void aTests::printline2log(const QString &log_name) { QString toWrite; toWrite.fill('=',60); toWrite+="\n"; QFile f; if(log_name==QString::null) { f.open( QIODevice::WriteOnly, stdout ); f.writeBlock((const char*)toWrite,strlen((const char*)toWrite)); } else { f.setName(log_name); f.open( QIODevice::WriteOnly | QIODevice::Append ); f.writeBlock((const char*)toWrite,strlen((const char*)toWrite)); f.flush(); } f.close(); }
void Bus::saveToFile(QFile &file) { QString s; QString t; // Comment s = QString("# Bus Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Bus") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + m_name + QString("\n"); file.writeBlock((const char*) s, s.length()); // ID t.setNum(m_id); s = QString("ID = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Type t.setNum(m_type); s = QString("Type = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Value t.setNum(m_value); s = QString("Value = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); }
void encode_decode_convenience_qba(bool encode, const Codec *codec, const QByteArray &infile_buffer, QFile &outfile) { QByteArray out; if(encode) out = codec->encode(infile_buffer, withCRLF); else out = codec->decode(infile_buffer, withCRLF); if(writing) { Q_LONG written = outfile.writeBlock(out); assert(written == (Q_LONG)out.size()); } }
void VirtualConsole::saveToFile(QFile& file) { QString s; QString t; // Comment s = QString("# Virtual Console Master Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Virtual Console") + QString("\n"); file.writeBlock((const char*) s, s.length()); // X t.setNum(rect().x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(rect().y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Width t.setNum(rect().width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Height t.setNum(rect().height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Default sliders if (m_dockArea->isHidden()) { s = QString("DefaultSliders = ") + Settings::falseValue() + QString("\n"); } else { s = QString("DefaultSliders = ") + Settings::trueValue() + QString("\n"); } file.writeBlock((const char*) s, s.length()); ASSERT(m_drawArea != NULL); m_drawArea->saveFramesToFile(file); m_drawArea->saveChildrenToFile(file); }
void Device::saveToFile(QFile &file) { QString s; QString t; // Comment s = QString("# Device Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Device") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + name() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Manufacturer s = QString("Manufacturer = ") + deviceClass()->manufacturer() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Model s = QString("Model = ") + deviceClass()->model() + QString("\n"); file.writeBlock((const char*) s, s.length()); // ID t.setNum(m_id); s = QString("ID = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Address t.setNum(address()); s = QString("Address = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Universe t.setNum(universe()); s = QString("Universe = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); }
void encode_decode_kio(bool encode, const Codec *codec, const QByteArray &infile_buffer, QFile &outfile) { Encoder *enc = 0; Decoder *dec = 0; // Get an encoder. This one you have to delete! if(encode) { enc = codec->makeEncoder(withCRLF); assert(enc); } else { dec = codec->makeDecoder(withCRLF); assert(dec); } QByteArray::ConstIterator iit = infile_buffer.begin(); QByteArray::ConstIterator iend = infile_buffer.end(); QByteArray out; do { out = QByteArray(); if(encode) encode_kio_internal(enc, iit, iend, out); else decode_kio_internal(dec, iit, iend, out); if(writing && out.size()) { Q_LONG written = outfile.writeBlock(out); assert(written == (Q_LONG)out.size()); } } while(out.size()); if(encode) delete enc; else delete dec; }
void VirtualConsole::saveToFile(QFile& file) { QString s; QString t; // Comment s = QString("# Virtual Console Master Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Virtual Console") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name t = (m_mode == Design) ? QString("Design") : QString("Operate"); s = QString("Mode = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // X t.setNum(rect().x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(rect().y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Width t.setNum(rect().width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Height t.setNum(rect().height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); ASSERT(m_drawArea != NULL); m_drawArea->saveFramesToFile(file); m_drawArea->saveChildrenToFile(file); }
/*! * \brief SimMessage::startSimulator simulates the document in view. */ void SimMessage::startSimulator() { // Using the Doc pointer here is risky as the user may have closed // the schematic, but converting the SPICE netlists is (hopefully) // faster than the user (I have no other idea). QString SimTime; QString Program; QStringList Arguments; QString SimPath = QDir::convertSeparators (QucsSettings.QucsHomeDir.absPath()); #ifdef __MINGW32__ QString QucsDigiLib = "qucsdigilib.bat"; QString QucsDigi = "qucsdigi.bat"; QString QucsVeri = "qucsveri.bat"; #else QString QucsDigiLib = "qucsdigilib"; QString QucsDigi = "qucsdigi"; QString QucsVeri = "qucsveri"; #endif SimOpt = NULL; bool isVerilog = false; // Simulate text window. if(DocWidget->inherits("QTextEdit")) { TextDoc * Doc = (TextDoc*)DocWidget; // Take VHDL file in memory as it could contain unsaved changes. Stream << Doc->toPlainText(); NetlistFile.close(); ProgText->insert(tr("done.")+"\n"); // of "creating netlist... // Simulation. if (Doc->simulation) { SimTime = Doc->SimTime; QString libs = Doc->Libraries.lower(); /// \todo \bug error: unrecognized command line option '-Wl' #ifdef __MINGW32__ if(libs.isEmpty()) { libs = ""; } else { libs.replace(" ",",-l"); libs = "-Wl,-l" + libs; } #else if(libs.isEmpty()) { libs = "-c"; } else { libs.replace(" ",",-l"); libs = "-c,-l" + libs; } #endif Program = pathName(QucsSettings.BinDir + QucsDigi); Arguments << QucsSettings.QucsHomeDir.filePath("netlist.txt") << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << libs; } // Module. else { QString text = Doc->toPlainText(); VHDL_File_Info VInfo (text); QString entity = VInfo.EntityName.lower(); QString lib = Doc->Library.lower(); if (lib.isEmpty()) lib = "work"; QString dir = QDir::convertSeparators (QucsSettings.QucsHomeDir.path()); QDir vhdlDir(dir); if(!vhdlDir.exists("vhdl")) if(!vhdlDir.mkdir("vhdl")) { ErrText->insert(tr("ERROR: Cannot create VHDL directory \"%1\"!") .arg(vhdlDir.path()+"/vhdl")); return; } vhdlDir.setPath(vhdlDir.path()+"/vhdl"); if(!vhdlDir.exists(lib)) if(!vhdlDir.mkdir(lib)) { ErrText->insert(tr("ERROR: Cannot create VHDL directory \"%1\"!") .arg(vhdlDir.path()+"/"+lib)); return; } vhdlDir.setPath(vhdlDir.path()+"/"+lib); QFile destFile; destFile.setName(vhdlDir.filePath(entity+".vhdl")); if(!destFile.open(QIODevice::WriteOnly)) { ErrText->insert(tr("ERROR: Cannot create \"%1\"!") .arg(destFile.name())); return; } destFile.writeBlock(text.ascii(), text.length()); destFile.close(); Program = pathName(QucsSettings.BinDir + QucsDigiLib); Arguments << QucsSettings.QucsHomeDir.filePath("netlist.txt") << pathName(SimPath) << entity << lib; } } // Simulate schematic window. else { // output NodeSets, SPICE simulations etc. for(QStringList::Iterator it = Collect.begin(); it != Collect.end(); ++it) { // don't put library includes into netlist... if ((*it).right(4) != ".lst" && (*it).right(5) != ".vhdl" && (*it).right(4) != ".vhd" && (*it).right(2) != ".v") { Stream << *it << '\n'; } } Stream << '\n'; isVerilog = ((Schematic*)DocWidget)->isVerilog; SimTime = ((Schematic*)DocWidget)->createNetlist(Stream, SimPorts); if(SimTime.length()>0&&SimTime.at(0) == '\xA7') { NetlistFile.close(); ErrText->insert(SimTime.mid(1)); FinishSimulation(-1); return; } if (isVerilog) { Stream << "\n" << " initial begin\n" << " $dumpfile(\"digi.vcd\");\n" << " $dumpvars();\n" << " #" << SimTime << " $finish;\n" << " end\n\n" << "endmodule // TestBench\n"; } NetlistFile.close(); ProgText->insert(tr("done.")+"\n"); // of "creating netlist... if(SimPorts < 0) { // append command arguments // append netlist with same arguments if (! Module::vaComponents.isEmpty()) { /*! Only pass modules to Qucsator that are indeed used on * the schematic,it might be the case that the user loaded the icons, * but did not compiled the module. Qucsator will not find the library. * * Check if used symbols have corresponing lib before running * Qucsator? Need to search on the netlis.txt? Is there other data * structure containig the netlist? * */ QStringList usedComponents; if (!NetlistFile.open(QIODevice::ReadOnly)) QMessageBox::critical(this, tr("Error"), tr("Cannot read netlist!")); else { QString net = QString(NetlistFile.readAll()); QMapIterator<QString, QString> i(Module::vaComponents); while (i.hasNext()) { i.next(); if (net.contains(i.key())) usedComponents << i.key(); } NetlistFile.close(); } if (! usedComponents.isEmpty()) { // \todo remvoe the command line arguments? use only netlist annotation? //Arguments << "-p" << QucsSettings.QucsWorkDir.absolutePath() // << "-m" << usedComponents; //qDebug() << "Command :" << Program << Arguments.join(" "); /// Anotate netlist with Verilog-A dynamic path and module names /// if (!NetlistFile.open(QFile::Append | QFile::Text)) QMessageBox::critical(this, tr("Error"), tr("Cannot read netlist!")); else { QTextStream out(&NetlistFile); out << "\n"; out << "# --path=" << QucsSettings.QucsWorkDir.absolutePath() << "\n"; out << "# --module=" << usedComponents.join(" ") << "\n"; NetlistFile.close(); } } } // vaComponents not empty if((SimOpt = findOptimization((Schematic*)DocWidget))) { ((Optimize_Sim*)SimOpt)->createASCOnetlist(); Program = QucsSettings.AscoBinDir.canonicalPath(); Program = QDir::toNativeSeparators(Program+"/"+"asco"+QString(executableSuffix)); Arguments << "-qucs" << QucsSettings.QucsHomeDir.filePath("asco_netlist.txt") << "-o" << "asco_out"; } else { Program = QucsSettings.BinDir + "qucsator" + executableSuffix; Arguments << "-b" << "-g" << "-i" << QucsSettings.QucsHomeDir.filePath("netlist.txt") << "-o" << DataSet; } } else { if (isVerilog) { Program = QDir::toNativeSeparators(QucsSettings.BinDir + QucsVeri); Arguments << QDir::toNativeSeparators(QucsSettings.QucsHomeDir.filePath("netlist.txt")) << DataSet << SimTime << QDir::toNativeSeparators(SimPath) << QDir::toNativeSeparators(QucsSettings.BinDir) << "-c"; } else { /// \todo \bug error: unrecognized command line option '-Wl' #ifdef __MINGW32__ Program = QDir::toNativeSeparators(pathName(QucsSettings.BinDir + QucsDigi)); Arguments << QDir::toNativeSeparators(QucsSettings.QucsHomeDir.filePath("netlist.txt")) << DataSet << SimTime << QDir::toNativeSeparators(SimPath) << QDir::toNativeSeparators(QucsSettings.BinDir) << "-Wall" << "-c"; #else Program = QDir::toNativeSeparators(pathName(QucsSettings.BinDir + QucsDigi)); Arguments << QucsSettings.QucsHomeDir.filePath("netlist.txt") << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << "-Wall" << "-c"; #endif } } } disconnect(&SimProcess, 0, 0, 0); connect(&SimProcess, SIGNAL(readyReadStandardError()), SLOT(slotDisplayErr())); connect(&SimProcess, SIGNAL(readyReadStandardOutput()), SLOT(slotDisplayMsg())); connect(&SimProcess, SIGNAL(finished(int)), SLOT(slotSimEnded(int))); #ifdef SPEEDUP_PROGRESSBAR waitForUpdate = false; #endif wasLF = false; ProgressText = ""; #ifdef __MINGW32__ QString sep(";"); // path separator #else QString sep(":"); #endif // append process PATH QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); // insert Qucs bin dir, so ASCO can find qucsator env.insert("PATH", env.value("PATH") + sep + QucsSettings.BinDir ); SimProcess.setProcessEnvironment(env); QFile file(Program); if ( !file.exists() ){ ErrText->insert(tr("ERROR: Program not found: %1").arg(Program)); FinishSimulation(-1); return; } else file.close(); qDebug() << "Command :" << Program << Arguments.join(" "); SimProcess.start(Program, Arguments); // launch the program if(!SimProcess.Running) { ErrText->insert(tr("ERROR: Cannot start simulator!")); FinishSimulation(-1); return; } }
void writeStr(QFile &f, const char *str) { f.writeBlock(str, strlen(str)); }
void VCFrame::saveFramesToFile(QFile& file, t_vc_id parentID) { QString s; QString t; // Comment s = QString("# Virtual Console Frame Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Frame") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + caption() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Parent ID if (parentID != 0) { t.setNum(parentID); s = QString("Parent = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Geometry if (m_bottomFrame == false) { // X t.setNum(x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // W t.setNum(width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // H t.setNum(height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Palette if (ownPalette()) { // Text color t.setNum(qRgb(paletteForegroundColor().red(), paletteForegroundColor().green(), paletteForegroundColor().blue())); s = QString("Textcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Background color t.setNum(qRgb(paletteBackgroundColor().red(), paletteBackgroundColor().green(), paletteBackgroundColor().blue())); s = QString("Backgroundcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Background pixmap if (paletteBackgroundPixmap()) { s = QString("Pixmap = " + iconText() + QString("\n")); file.writeBlock((const char*) s, s.length()); } // Font s = QString("Font = ") + font().toString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Frame if (frameStyle() & KFrameStyle) { s = QString("Frame = ") + Settings::trueValue() + QString("\n"); } else { s = QString("Frame = ") + Settings::falseValue() + QString("\n"); } file.writeBlock((const char*) s, s.length()); // Button Behaviour t.setNum(m_buttonBehaviour); s = QString("ButtonBehaviour = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // ID t.setNum(id()); s = QString("ID = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); if (children() != NULL) { QObjectList* ol = (QObjectList*) children(); QObjectListIt it(*ol); // Child frames for (; it.current() != NULL; ++it) { if (QString(it.current()->className()) == QString("VCFrame")) { VCFrame* w = (VCFrame*) it.current(); w->saveFramesToFile(file, id()); } } } }
// ------------------------------------------------------------------------ void SimMessage::startSimulator() { // Using the Doc pointer here is risky as the user may have closed // the schematic, but converting the SPICE netlists is (hopefully) // faster than the user (I have no other idea). QString SimTime; QString Program; QStringList Arguments; QString SimPath = QDir::convertSeparators (QucsHomeDir.absPath()); #ifdef __MINGW32__ QString QucsDigiLib = "qucsdigilib.bat"; QString QucsDigi = "qucsdigi.bat"; QString QucsVeri = "qucsveri.bat"; #else QString QucsDigiLib = "qucsdigilib"; QString QucsDigi = "qucsdigi"; QString QucsVeri = "qucsveri"; #endif SimOpt = NULL; bool isVerilog = false; // Simulate text window. if(DocWidget->inherits("QTextEdit")) { TextDoc * Doc = (TextDoc*)DocWidget; // Take VHDL file in memory as it could contain unsaved changes. Stream << Doc->text(); NetlistFile.close(); ProgText->insert(tr("done.")+"\n"); // of "creating netlist... // Simulation. if (Doc->simulation) { SimTime = Doc->SimTime; QString libs = Doc->Libraries.lower(); #ifdef __MINGW32__ if(libs.isEmpty()) { libs = "-Wl"; } else { libs.replace(" ",",-l"); libs = "-Wl,-l" + libs; } #else if(libs.isEmpty()) { libs = "-c"; } else { libs.replace(" ",",-l"); libs = "-c,-l" + libs; } #endif Program = pathName(QucsSettings.BinDir + QucsDigi); Arguments << "netlist.txt" << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << libs; } // Module. else { QString text = Doc->text(); VHDL_File_Info VInfo (text); QString entity = VInfo.EntityName.lower(); QString lib = Doc->Library.lower(); if (lib.isEmpty()) lib = "work"; QString dir = QDir::convertSeparators (QucsHomeDir.path()); QDir vhdlDir(dir); if(!vhdlDir.exists("vhdl")) if(!vhdlDir.mkdir("vhdl")) { ErrText->insert(tr("ERROR: Cannot create VHDL directory \"%1\"!") .arg(vhdlDir.path()+"/vhdl")); return; } vhdlDir.setPath(vhdlDir.path()+"/vhdl"); if(!vhdlDir.exists(lib)) if(!vhdlDir.mkdir(lib)) { ErrText->insert(tr("ERROR: Cannot create VHDL directory \"%1\"!") .arg(vhdlDir.path()+"/"+lib)); return; } vhdlDir.setPath(vhdlDir.path()+"/"+lib); QFile destFile; destFile.setName(vhdlDir.filePath(entity+".vhdl")); if(!destFile.open(QIODevice::WriteOnly)) { ErrText->insert(tr("ERROR: Cannot create \"%1\"!") .arg(destFile.name())); return; } destFile.writeBlock(text.ascii(), text.length()); destFile.close(); Program = pathName(QucsSettings.BinDir + QucsDigiLib); Arguments << "netlist.txt" << pathName(SimPath) << entity << lib; } } // Simulate schematic window. else { // output NodeSets, SPICE simulations etc. for(QStringList::Iterator it = Collect.begin(); it != Collect.end(); ++it) { // don't put library includes into netlist... if ((*it).right(4) != ".lst" && (*it).right(5) != ".vhdl" && (*it).right(4) != ".vhd" && (*it).right(2) != ".v") { Stream << *it << '\n'; } } Stream << '\n'; isVerilog = ((Schematic*)DocWidget)->isVerilog; SimTime = ((Schematic*)DocWidget)->createNetlist(Stream, SimPorts); if(SimTime.length()>0&&SimTime.at(0) == '\xA7') { NetlistFile.close(); ErrText->insert(SimTime.mid(1)); FinishSimulation(-1); return; } if (isVerilog) { Stream << "\n" << " initial begin\n" << " $dumpfile(\"digi.vcd\");\n" << " $dumpvars();\n" << " #" << SimTime << " $finish;\n" << " end\n\n" << "endmodule // TestBench\n"; } NetlistFile.close(); ProgText->insert(tr("done.")+"\n"); // of "creating netlist... if(SimPorts < 0) { if((SimOpt = findOptimization((Schematic*)DocWidget))) { ((Optimize_Sim*)SimOpt)->createASCOnetlist(); Program = QucsSettings.AscoDir + "asco"+ executablePostfix; Arguments << "-qucs" << QucsHomeDir.filePath("asco_netlist.txt") << "-o" << "asco_out"; } else { Program = QucsSettings.BinDir + "qucsator" + executablePostfix; Arguments << "-b" << "-g" << "-i" << QucsHomeDir.filePath("netlist.txt") << "-o" << DataSet; } } else { if (isVerilog) { Program = pathName(QucsSettings.BinDir + QucsVeri); Arguments << "netlist.txt" << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << "-c"; } else { #ifdef __MINGW32__ Program = pathName(QucsSettings.BinDir + QucsDigi); Arguments << "netlist.txt" << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << "-Wl" << "-c"; #else Program = pathName(QucsSettings.BinDir + QucsDigi); Arguments << "netlist.txt" << DataSet << SimTime << pathName(SimPath) << pathName(QucsSettings.BinDir) << "-Wall" << "-c"; #endif } } } disconnect(&SimProcess, 0, 0, 0); connect(&SimProcess, SIGNAL(readyReadStandardError()), SLOT(slotDisplayErr())); connect(&SimProcess, SIGNAL(readyReadStandardOutput()), SLOT(slotDisplayMsg())); connect(&SimProcess, SIGNAL(finished(int)), SLOT(slotSimEnded(int))); #ifdef SPEEDUP_PROGRESSBAR waitForUpdate = false; #endif wasLF = false; ProgressText = ""; #ifdef __MINGW32__ QString sep(";"); // path separator #else QString sep(":"); #endif // append process PATH QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("PATH", env.value("PATH") + sep + QucsSettings.BinDir ); SimProcess.setProcessEnvironment(env); QFile file(Program); if ( !file.exists() ){ ErrText->insert(tr("ERROR: Program not found: %1").arg(Program)); FinishSimulation(-1); return; } else file.close(); SimProcess.start(Program, Arguments); // launch the program if(!SimProcess.Running) { ErrText->insert(tr("ERROR: Cannot start simulator!")); FinishSimulation(-1); return; } }
void VCLabel::saveToFile(QFile& file, unsigned int parentID) { QString s; QString t; // Comment s = QString("# Virtual Console Label Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Label") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + caption() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Parent ID t.setNum(parentID); s = QString("Parent = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // X t.setNum(x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // W t.setNum(width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // H t.setNum(height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Text color if (ownPalette()) { t.setNum(qRgb(paletteForegroundColor().red(), paletteForegroundColor().green(), paletteForegroundColor().blue())); s = QString("Textcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Background color t.setNum(qRgb(paletteBackgroundColor().red(), paletteBackgroundColor().green(), paletteBackgroundColor().blue())); s = QString("Backgroundcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Background pixmap if (paletteBackgroundPixmap()) { s = QString("Pixmap = " + iconText() + QString("\n")); file.writeBlock((const char*) s, s.length()); } // Font s = QString("Font = ") + font().toString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Frame if (frameStyle() & KFrameStyle) { s = QString("Frame = ") + Settings::trueValue() + QString("\n"); } else { s = QString("Frame = ") + Settings::falseValue() + QString("\n"); } file.writeBlock((const char*) s, s.length()); }
// // Save settings to file // void VCDockSlider::saveToFile(QFile &file, t_vc_id parentID) { QString s; QString t; // Comment s = QString("# Virtual Console Slider Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Slider") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + caption() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Parent ID t.setNum(parentID); s = QString("Parent = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // X t.setNum(x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // W t.setNum(width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // H t.setNum(height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Text color if (ownPalette()) { t.setNum(qRgb(paletteForegroundColor().red(), paletteForegroundColor().green(), paletteForegroundColor().blue())); s = QString("Textcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); t.setNum(qRgb(paletteBackgroundColor().red(), paletteBackgroundColor().green(), paletteBackgroundColor().blue())); s = QString("Backgroundcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Background pixmap if (paletteBackgroundPixmap()) { s = QString("Pixmap = " + iconText() + QString("\n")); file.writeBlock((const char*) s, s.length()); } // Frame if (frameStyle() & KFrameStyle) { s = QString("Frame = ") + Settings::trueValue() + QString("\n"); } else { s = QString("Frame = ") + Settings::falseValue() + QString("\n"); } file.writeBlock((const char*) s, s.length()); // Font s = QString("Font = ") + font().toString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Bus t.setNum(m_busID); s = QString("Bus = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Bus Lo t.setNum(m_busLowLimit); s = QString("BusLowLimit = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Bus Hi t.setNum(m_busHighLimit); s = QString("BusHighLimit = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Channels if (m_channels.count()) { s = QString("Channels = "); QValueList<t_channel>::Iterator it; for (it = m_channels.begin(); it != m_channels.end(); ++it) { t.sprintf("%.3d", *it); s += t + QString(" "); } s += QString("\n"); file.writeBlock((const char*) s, s.length()); } // Level Lo t.setNum(m_levelLowLimit); s = QString("LevelLowLimit = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Level Hi t.setNum(m_levelHighLimit); s = QString("LevelHighLimit = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Mode (must be written after bus & channel settings) s = QString("Mode = ") + modeString(m_mode) + QString("\n"); file.writeBlock((const char*) s, s.length()); // Value t.setNum(m_slider->value()); s = QString("Value = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); }
void CiteDict::generatePage() const { //printf("** CiteDict::generatePage() count=%d\n",m_ordering.count()); // do not generate an empty citations page if (isEmpty()) return; // nothing to cite // 1. generate file with markers and citations to OUTPUT_DIRECTORY QFile f; QCString outputDir = Config_getString("OUTPUT_DIRECTORY"); QCString citeListFile = outputDir+"/citelist.doc"; f.setName(citeListFile); if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",citeListFile.data()); } FTextStream t(&f); t << "<!-- BEGIN CITATIONS -->" << endl; t << "<!--" << endl; QDictIterator<CiteInfo> it(m_entries); CiteInfo *ci; for (it.toFirst();(ci=it.current());++it) { t << "\\citation{" << ci->label << "}" << endl; } t << "-->" << endl; t << "<!-- END CITATIONS -->" << endl; t << "<!-- BEGIN BIBLIOGRAPHY -->" << endl; t << "<!-- END BIBLIOGRAPHY -->" << endl; f.close(); // 2. generate bib2xhtml QCString bib2xhtmlFile = outputDir+"/bib2xhtml.pl"; f.setName(bib2xhtmlFile); QCString bib2xhtml = bib2xhtml_pl; if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",bib2xhtmlFile.data()); } f.writeBlock(bib2xhtml, bib2xhtml.length()); f.close(); // 3. generate doxygen.bst QCString doxygenBstFile = outputDir+"/doxygen.bst"; QCString bstData = doxygen_bst; f.setName(doxygenBstFile); if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",doxygenBstFile.data()); } f.writeBlock(bstData, bstData.length()); f.close(); // 4. for html we just copy the bib files to the output so that // bibtex can find them without path (bibtex doesn't support path's // with spaces!) QList<QCString> tempFiles; tempFiles.setAutoDelete(TRUE); QDir thisDir; if (Config_getBool("GENERATE_HTML")) { // copy bib files to the latex output dir QStrList &citeDataList = Config_getList("CITE_BIB_FILES"); QCString bibOutputDir = outputDir+"/"; QFileInfo fo(bibOutputDir); const char *bibdata = citeDataList.first(); while (bibdata) { QCString bibFile = bibdata; if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib"; QFileInfo fi(bibFile); if (fi.exists() && fi.dirPath(TRUE)!=fo.absFilePath()) { if (!bibFile.isEmpty()) { QCString destFile=bibOutputDir+fi.fileName().data(); copyFile(bibFile,destFile); tempFiles.append(new QCString(destFile)); } } else if (!fi.exists()) { err("bib file %s not found!\n",bibFile.data()); } bibdata = citeDataList.next(); } } QCString oldDir = QDir::currentDirPath().utf8(); QDir::setCurrent(outputDir); // 5. run bib2xhtml perl script on the generated file which will insert the // bibliography in citelist.doc portable_system("perl","\""+bib2xhtmlFile+"\" "+getListOfBibFiles(" ",FALSE)+" \""+ citeListFile+"\""); QDir::setCurrent(oldDir); // 6. read back the file f.setName(citeListFile); if (!f.open(IO_ReadOnly)) { err("could not open file %s/citelist.doc for reading\n",outputDir.data()); } bool insideBib=FALSE; QCString doc; QFileInfo fi(citeListFile); QCString input(fi.size()+1); f.readBlock(input.data(),fi.size()); f.close(); input.at(fi.size())='\0'; int p=0,s; //printf("input=[%s]\n",input.data()); while ((s=input.find('\n',p))!=-1) { QCString line = input.mid(p,s-p); //printf("p=%d s=%d line=[%s]\n",p,s,line.data()); p=s+1; if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE; else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE; else if (insideBib) doc+=line+"\n"; int i; // determine text to use at the location of the @cite command if (insideBib && (i=line.find("<a name=\"CITEREF_"))!=-1) { int j=line.find("\">["); int k=line.find("]</a>"); if (j!=-1 && k!=-1) { QCString label = line.mid(i+17,j-i-17); QCString number = line.mid(j+2,k-j-1); CiteInfo *ci = m_entries.find(label); //printf("label='%s' number='%s' => %p\n",label.data(),number.data(),ci); if (ci) { ci->text = number; } } } } //printf("doc=[%s]\n",doc.data()); // 7. add it as a page addRelatedPage(CiteConsts::fileName, theTranslator->trCiteReferences(),doc,0,CiteConsts::fileName,1,0,0,0); // 8. for latex we just copy the bib files to the output and let // latex do this work. if (Config_getBool("GENERATE_LATEX")) { // copy bib files to the latex output dir QStrList &citeDataList = Config_getList("CITE_BIB_FILES"); QCString latexOutputDir = Config_getString("LATEX_OUTPUT")+"/"; const char *bibdata = citeDataList.first(); while (bibdata) { QCString bibFile = bibdata; if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib"; QFileInfo fi(bibFile); if (fi.exists()) { if (!bibFile.isEmpty()) { copyFile(bibFile,latexOutputDir+fi.fileName().data()); } } else { err("bib file %s not found!\n",bibFile.data()); } bibdata = citeDataList.next(); } } // 9. Remove temporary files thisDir.remove(citeListFile); thisDir.remove(doxygenBstFile); thisDir.remove(bib2xhtmlFile); while (!tempFiles.isEmpty()) { QCString *s=tempFiles.take(0); thisDir.remove(*s); } }
//===================================== // main program... //------------------------------------- int main(int argc,char*argv[]) { //===================================== // init variables... //------------------------------------- bool uniFont = false; bool noBorder = false; bool fastSetup = false; bool withDialog = false; bool yastMode = false; bool useHwData = false; bool fullScreen = false; bool setInfo = false; bool set3D = false; bool setXIdle = false; bool checkPacs = false; for (int n=0;n<argc;n++) { if (strcmp(argv[n],"-style") == 0) { globalStyle = (char*) malloc (sizeof(char) * 128); sprintf(globalStyle,"%s",argv[n+1]); break; } } //===================================== // check for root priviliges... //------------------------------------- if (! accessAllowed()) { fprintf (stderr,"xapi: only root can do this\n"); usage(); } //===================================== // start logging... //------------------------------------- logInit(); //===================================== // allocate main qt object... //------------------------------------- for (int i=0;i<argc;i++) { QString item (argv[i]); if ((item == "-h") || (item == "--help")) { logExit(); usage(); exit(0); } } QApplication app(argc,argv); //===================================== // get additional options... //------------------------------------- QString* idlePID = NULL; QString* cardName3D = NULL; QString* popUpDialog = NULL; QString* cardDriver = NULL; while (1) { int option_index = 0; static struct option long_options[] = { {"usehwdata" , 0 , 0 , 'u'}, {"fullscreen" , 0 , 0 , 'l'}, {"info" , 0 , 0 , 'i'}, {"yast" , 0 , 0 , 'y'}, {"checkpacs" , 0 , 0 , 'c'}, {"noborder" , 0 , 0 , 'n'}, {"3d" , 1 , 0 , 'D'}, {"driver" , 1 , 0 , 'd'}, {"frameWidth" , 1 , 0 , 'w'}, {"dialog" , 1 , 0 , 'O'}, {"unifont" , 0 , 0 , 'U'}, {"xidle" , 0 , 0 , 'x'}, {"pid" , 1 , 0 , 'p'}, {"fast" , 0 , 0 , 'f'}, {"help" , 0 , 0 , 'h'}, {0 , 0 , 0 , 0 } }; int c = getopt_long ( argc, argv, "uicD:fhxlw:d:yp:nUO:",long_options, &option_index ); if (c == -1) break; switch (c) { case 0: fprintf (stderr,"xapi: option %s", long_options[option_index].name); if (optarg) fprintf (stderr," with arg %s", optarg); fprintf (stderr,"\n"); break; case 'f': fastSetup = true; break; case 'U': uniFont = true; break; case 'O': withDialog = true; popUpDialog = new QString (optarg); break; case 'n': noBorder = true; break; case 'y': yastMode = true; break; case 'w': globalFrameWidth = atoi (optarg); break; case 'u': useHwData = true; break; case 'l': fullScreen = true; break; case 'i': setInfo = true; break; case 'c': checkPacs = true; break; case 'D': set3D = true; cardName3D = new QString (optarg); break; case 'p': idlePID = new QString (optarg); break; case 'd': cardDriver = new QString (optarg); break; case 'x': setXIdle = true; break; case 'h': logExit(); usage(); break; default: logExit(); exit(1); } } //===================================== // check if xapi should act as xidle //------------------------------------- if (setXIdle) { XTimeElapsed* idleTimer = new XTimeElapsed ( idlePID ); app.setMainWidget (idleTimer); idleTimer->show(); return app.exec(); } //===================================== // check md5 sum of current config //------------------------------------- if ((! setInfo) && (! set3D) && (! checkPacs) && (! useHwData) && (! fastSetup) ) { bool createMD5sum = false; QFileInfo xc (MD5CONFIG); if (xc.exists()) { QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG); QFile mHandle (MD5CONFIG); if (mHandle.open(IO_ReadOnly)) { QString compare; mHandle.readLine(compare,MAX_LINE_LENGTH); mHandle.close(); compare = compare.stripWhiteSpace(); if (compare == mD5Sum) { fastSetup = true; } else { fastSetup = false; } } } else { fastSetup = false; } if (createMD5sum) { QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG); QFile mHandle (MD5CONFIG); if (mHandle.open(IO_WriteOnly)) { mHandle.writeBlock (mD5Sum.ascii(),mD5Sum.length()); mHandle.close(); } } } //===================================== // check option combinations... //------------------------------------- if (useHwData == true) { fastSetup = false; } //===================================== // set root window cursor to the watch //------------------------------------- setMouseCursor ("watch"); //===================================== // init program... //------------------------------------- QWidget::WFlags wflags = Qt::WType_TopLevel; if (noBorder) { wflags |= Qt::WStyle_Customize | Qt::WStyle_NoBorder; } if (uniFont) { QFont currentFont = QFont( "Helvetica", 12 ); currentFont.setStyleHint( QFont::SansSerif, QFont::PreferBitmap ); currentFont.setRawName (UNIFONT); qApp->setFont (currentFont); } xapi = new XFrame ( globalFrameWidth, wflags ); if (setInfo) { signal (SIGHUP ,gotKill); signal (SIGKILL,gotKill); signal (SIGABRT,gotKill); signal (SIGTERM,gotKill); XInfo infoBox (xapi); infoBox.showIntroBox(); logExit(); setMouseCursor (); exit ( infoBox.returnCode() ); } if (set3D) { XInfo infoBox (xapi); infoBox.show3DBox (*cardName3D,cardDriver); printf("%d\n",infoBox.returnCode()); logExit(); setMouseCursor (); exit ( infoBox.returnCode() ); } if (fastSetup) { xapi->fastSetup = true; } if (useHwData) { xapi->useHwData = true; } if (fullScreen) { xapi->fullScreen = true; } if (yastMode) { xapi->yastMode = true; } //===================================== // check 3D environment //------------------------------------- XStringList packageInfo ( qx (GET3D,STDOUT) ); packageInfo.setSeperator (":"); QString package = packageInfo.getList().at(0); QString real3d = packageInfo.getList().at(1); QString soft3d = packageInfo.getList().at(2); QString general = packageInfo.getList().at(3); QString active = packageInfo.getList().at(4); QString answer = packageInfo.getList().at(5); QString flag = packageInfo.getList().at(6); global3DActive = active.toInt(); QString status1 ("1"); if (checkPacs) { // ... // if the 3D Answer was no, there is no need // to check for any packages or scripts // --- if (answer == "no") { setMouseCursor (); exit (0); } // ... // install the missing packages using YaST2 // sw_single mode // --- if (package != "<none>") { if (setMessage("InstallPackage",xapi)) { status1 = qx ( GETINSTALLED,STDOUT,1,"%s",package.ascii() ); } } setMouseCursor (); exit (0); } //===================================== // remove lilo code file... //------------------------------------- unlink (LILOCODE); //===================================== // init main frame... //------------------------------------- if (! xapi->frameInitialized()) { xapi->setFrame (); } //===================================== // set signal handler... //------------------------------------- signal (SIGUSR2,SIG_IGN); signal (SIGINT ,gotInterrupted); //===================================== // init dialogs... //------------------------------------- XIntro* intro = new XIntro(); XAccessX* xaccess = new XAccessX(); XMouse* mouse = new XMouse(); XCard* card = new XCard(); XDesktop* desktop = new XDesktop(); XDisplayGeometry* geo = new XDisplayGeometry(); XKeyboard* keyboard = new XKeyboard(); XLayout* layout = new XLayout(); XMonitor* monitor = new XMonitor(); XMultihead* multi = new XMultihead(); XTablet* tablet = new XTablet(); XTouchScreen* toucher = new XTouchScreen(); XOpenGL* opengl = new XOpenGL(); XVirtual* virtuals = new XVirtual(); Xvnc* vnc = new Xvnc(); intro -> addTo (xapi); xaccess -> addTo (xapi,intro); mouse -> addTo (xapi,intro); card -> addTo (xapi,intro); desktop -> addTo (xapi,intro); geo -> addTo (xapi,intro); keyboard -> addTo (xapi,intro); layout -> addTo (xapi,intro); monitor -> addTo (xapi,intro); multi -> addTo (xapi,intro); tablet -> addTo (xapi,intro); toucher -> addTo (xapi,intro); opengl -> addTo (xapi,intro); virtuals -> addTo (xapi,intro); vnc -> addTo (xapi,intro); //===================================== // save intro pointer... //------------------------------------- introPointer = intro; //===================================== // make sure the serverlayout structure // is created at least one time //------------------------------------- XLayout* layoutDialog; layoutDialog = (XLayout*) intro -> retrieve (Layout); layoutDialog -> setupLayout(); //===================================== // make sure the card dialog was build // in init stage //------------------------------------- XCard* cardDialog; cardDialog = (XCard*) intro -> retrieve (Card); cardDialog -> showSetupWindow (false); cardDialog -> slotRun (Card); cardDialog -> showSetupWindow (true); //===================================== // call resetPage of the desktop dialog // to check for framebuffer usage //------------------------------------- XDesktop* desktopDialog; desktopDialog = (XDesktop*) intro -> retrieve (Colors); desktopDialog -> resetPage ( PAGE_RELOAD ); //===================================== // add margin around pushbutton texts // this is only needed for QT3 //------------------------------------- #if 1 QObject* obj; QObjectList* l = xapi->queryList( "QPushButton" ); QObjectListIt it( *l ); QDict<char>* mText = xapi->getTextPointer(); while ( (obj=it.current()) != 0 ) { ++it; QPushButton* btn = (QPushButton*) obj; QString text = btn->text(); if (! text.isNull()) { QDictIterator<char> n (*mText); for (; n.current(); ++n) { if (n.current() == text) { QString* newText = new QString(); QTextOStream (newText) << " " << text << " "; mText->replace (n.currentKey(),*newText); break; } } QString addText; QTextOStream (&addText) << " " << text << " "; btn->setText (addText); } } delete l; // ... // special keys which are used dynamically on widgets // with initially other texts // --- QList<char> keyList; keyList.append ( "finish" ); keyList.append ( "Next" ); QListIterator<char> io ( keyList ); for (; io.current(); ++io) { QString key ( io.current() ); QString curText (mText->operator[](key)); QString* newText = new QString(); QTextOStream (newText) << " " << curText << " "; mText->replace (key,*newText); } #endif //===================================== // remove xfine cache directory... //------------------------------------- removeXFineCache(); //===================================== // go to main event loop... //------------------------------------- app.setMainWidget(xapi); xapi -> show(); xapi -> enterEvent ( 0 ); xapi -> activateFirstItem(); setMouseCursor(); if (! withDialog) { intro -> checkDetected(); } else { if ( *popUpDialog == "Monitor" ) { xapi -> runDialog (Monitor); } else if ( *popUpDialog == "Card") { xapi -> runDialog (Card); } else { fprintf (stderr,"xapi: no such dialog: %s\n",popUpDialog->ascii()); exit (1); } } return app.exec(); }
void encode_decode_chunkwise(bool encode, const Codec *codec, const QByteArray &infile_buffer, QFile &outfile) { Encoder *enc = 0; Decoder *dec = 0; QByteArray indata(inbufsize); QByteArray outdata(outbufsize); // we're going to need this below: #define write_full_outdata_then_reset do { \ kdDebug( verbose ) << " flushing output buffer." << endl; \ if ( writing ) { \ Q_LONG outlen = outfile.writeBlock( outdata.data(), \ outdata.size() ); \ if ( outlen != (int)outdata.size() ) \ exit(OUTFILE_WRITE_ERR); \ } \ oit = outdata.begin(); \ } while ( false ) #define report_status(x,y) do { \ kdDebug( verbose ) << " " #x "() returned " #y " after processing " \ << iit - indata.begin() << " bytes of input.\n" \ << " output iterator now at position " \ << oit - outdata.begin() << " of " \ << outdata.size() << endl; \ } while ( false ) #define report_finish_status(y) do { \ kdDebug( verbose ) << " finish() returned " #y "\n" \ << " output iterator now at position " \ << oit - outdata.begin() << " of " \ << outdata.size() << endl; \ } while ( false ) // Initialize the output iterators: QByteArray::Iterator oit = outdata.begin(); QByteArray::Iterator oend = outdata.end(); // Get an encoder. This one you have to delete! if(encode) { enc = codec->makeEncoder(withCRLF); assert(enc); } else { dec = codec->makeDecoder(withCRLF); assert(dec); } // // Loop over input chunks: // uint offset = 0; while(offset < infile_buffer.size()) { uint reallyRead = QMIN(indata.size(), infile_buffer.size() - offset); indata.duplicate(infile_buffer.begin() + offset, reallyRead); offset += reallyRead; kdDebug(verbose) << " read " << reallyRead << " bytes (max: " << indata.size() << ") from input." << endl; // setup input iterators: QByteArray::ConstIterator iit = indata.begin(); QByteArray::ConstIterator iend = indata.begin() + reallyRead; if(encode) { // // Loop over encode() calls: // while(!enc->encode(iit, iend, oit, oend)) { report_status(encode, false); if(oit == oend) // output buffer full: write_full_outdata_then_reset; } report_status(encode, true); } else { // // Loop over decode() calls: // while(!dec->decode(iit, iend, oit, oend)) { report_status(decode, false); if(oit == oend) // output buffer full: write_full_outdata_then_reset; } report_status(decode, true); } } // end loop over input chunks // // Now finish the encoding/decoding: // (same loops as above, just s/encode|decode/finish()) // if(withFinish) if(encode) { while(!enc->finish(oit, oend)) { report_finish_status(false); if(oit == oend) write_full_outdata_then_reset; } report_finish_status(true); } else { while(!dec->finish(oit, oend)) { report_finish_status(false); if(oit == oend) write_full_outdata_then_reset; } report_finish_status(true); } // // Write out last (partial) output chunk: // if(writing) { Q_LONG outlen = outfile.writeBlock(outdata.data(), oit - outdata.begin()); if(outlen != oit - outdata.begin()) exit(OUTFILE_WRITE_ERR); } // // Delete en/decoder: // if(encode) delete enc; else delete dec; }
void VCButton::saveToFile(QFile& file, unsigned int parentID) { QString s; QString t; // Comment s = QString("# Virtual Console Button Entry\n"); file.writeBlock((const char*) s, s.length()); // Entry type s = QString("Entry = Button") + QString("\n"); file.writeBlock((const char*) s, s.length()); // Name s = QString("Name = ") + caption() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Parent ID t.setNum(parentID); s = QString("Parent = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // X t.setNum(x()); s = QString("X = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Y t.setNum(y()); s = QString("Y = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // W t.setNum(width()); s = QString("Width = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // H t.setNum(height()); s = QString("Height = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Text color if (ownPalette()) { t.setNum(qRgb(paletteForegroundColor().red(), paletteForegroundColor().green(), paletteForegroundColor().blue())); s = QString("Textcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); // Background color t.setNum(qRgb(paletteBackgroundColor().red(), paletteBackgroundColor().green(), paletteBackgroundColor().blue())); s = QString("Backgroundcolor = ") + t + QString("\n"); file.writeBlock((const char*) s, s.length()); } // Background pixmap if (paletteBackgroundPixmap()) { s = QString("Pixmap = " + iconText() + QString("\n")); file.writeBlock((const char*) s, s.length()); } // Font s = QString("Font = ") + font().toString() + QString("\n"); file.writeBlock((const char*) s, s.length()); // Function s.sprintf("Function = %d\n", m_functionID); file.writeBlock((const char*) s, s.length()); // Key binding assert(m_keyBind); s.sprintf("BindKey = %d\n", m_keyBind->key()); file.writeBlock((const char*) s, s.length()); s.sprintf("BindMod = %d\n", m_keyBind->mod()); file.writeBlock((const char*) s, s.length()); s.sprintf("BindPress = %d\n", m_keyBind->pressAction()); file.writeBlock((const char*) s, s.length()); s.sprintf("BindRelease = %d\n", m_keyBind->releaseAction()); file.writeBlock((const char*) s, s.length()); }