From 7fcde3393eb2150fd96f7899056ec11d0fd2931e Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 12 Sep 2004 20:24:05 +0000 Subject: writing gammurc added --- (limited to 'libkcal/phoneformat.cpp') diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 178a63e..99d6a06 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -84,9 +84,98 @@ public: PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) { mProfileName = profileName; - mDevice = device; - mConnection = connection; - mModel = model; + + QString fileName = QDir::homeDirPath() +"/.gammurc"; + //qDebug("save %d ", load ); + QString content; + bool write = false; + bool addPort = true, addConnection = true, addModel = true; + QFile file( fileName ); + if ( QFile::exists( fileName) ) { + if (!file.open( IO_ReadOnly ) ) { + qDebug("Error: cannot open %s ", fileName.latin1() ); + return; + } + QString line; + while ( file.readLine( line, 1024 ) > 0 ) { + //qDebug("*%s* ", line.latin1() ); + if ( line.left(7 ) == "[gammu]" ) { + ; + } else + if ( line.left(4 ) == "port" ) { + if ( line == "port = " + device+"\n" ) { + content += line ; + addPort = false; + //qDebug("port found" ); + } + + } else if ( line.left(5 ) == "model" ) { + if ( line == "model = " + model +"\n") { + content += line ; + addModel = false; + //qDebug("model found" ); + } + + } else if ( line.left( 10 ) == "connection" ) { + if ( line == "connection = " + connection +"\n") { + addConnection = false; + content += line ; + //qDebug("con found" ); + } + + } else { + content += line ; + } + } + file.close(); + } else { + if ( ! connection.isEmpty() ) { + addConnection = true; + } + if ( ! device.isEmpty() ) { + addPort = true; + + } + if ( ! model.isEmpty() ) { + addModel = true; + } + } + + if ( addConnection ) { + if ( ! write ) + content += "[gammu]\n"; + write = true; + content += "connection = "; + content += connection; + content += "\n"; + } + if ( addPort ) { + if ( ! write ) + content += "[gammu]\n"; + write = true; + content += "port = "; + content += device; + content += "\n"; + + } + if ( addModel ) { + if ( ! write ) + content += "[gammu]\n"; + write = true; + content += "model = "; + content += model; + content += "\n"; + } + if ( write ) { + if (!file.open( IO_WriteOnly ) ) { + qDebug("Error: cannot write file %s ", fileName.latin1() ); + return; + } + qDebug("Writing file %s ", fileName.latin1() ); + QTextStream ts( &file ); + ts << content ; + file.close(); + } } PhoneFormat::~PhoneFormat() -- cgit v0.9.0.2