summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/kmolcalc.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/oxygen/kmolcalc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolcalc.cpp40
1 files changed, 2 insertions, 38 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.cpp b/noncore/apps/oxygen/kmolcalc.cpp
index 7257c4a..0ba52da 100644
--- a/noncore/apps/oxygen/kmolcalc.cpp
+++ b/noncore/apps/oxygen/kmolcalc.cpp
@@ -1,16 +1,16 @@
/*
* kmolcalc.cpp
*
- * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
+ * Copyright (C) 2000,2001 Tomislav Gountchev <tomi@idiom.com>
* Copyright (C) 2002 Carsten Niehaus <cniehaus@handhelds.org>
*/
/**
* KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
* weights and group definitions ELSTABLE, and the currently processed formula, stored
* as a list of elements and their coefficients, ELEMENTS.
*/
#include "kmolcalc.h"
#include <qdict.h>
#include <qdir.h>
@@ -27,46 +27,27 @@ KMolCalc::KMolCalc() {
readElstable();
}
KMolCalc::~KMolCalc() {
delete elements;
}
void KMolCalc::readElstable() {
weight = -1; // not calculated yet
if (elstable) delete elstable;
elstable = new QDict<SubUnit> (197, TRUE);
elstable->setAutoDelete(TRUE);
- QStringList files = "/home/opie/opie/noncore/apps/oxigen/kmolweights";
- mwfile = "/home/opie/opie/noncore/apps/oxigen/kmolweights";
+ mwfile = "/home/opie/opie/noncore/apps/oxygen/kmolweights";
QFile f(mwfile);
- QString* latest_f = &mwfile;
- for (uint i=0; i<files.count(); i++) {
- if (QFileInfo(QFile(files[i])).lastModified() > QFileInfo(QFile(*latest_f)).lastModified()) {
- latest_f = &files[i];
- }
- }
- QFile lf(*latest_f);
if (f.exists()) readMwfile(f);
- if (!f.exists()) {
- readMwfile(lf);
- writeElstable();
- } else if (QFileInfo(f).lastModified() < QFileInfo(lf).lastModified()) {
- // announce
- QMessageBox::information
- (0, "Warning:", "Found new global Mw file.\nLocal definitions will be updated.", QMessageBox::Ok);
- readMwfile(lf);
- writeElstable();
- }
-
}
/**
* Parse a string S and construct the ElementList this->ELEMENTS, representing the
* composition of S. Returns 0 if successful, or an error code (currently -1) if
* parsing failed.
* The elements is S must be valid element or group symbols, as stored in this->ELSTABLE.
* See help files for correct formula syntax.
*/
QString KMolCalc::readFormula(const QString& s) {
weight = -1;
@@ -179,41 +160,24 @@ void KMolCalc::readMwfile(QFile& f) {
if (! f.open(IO_ReadOnly)) return; //ERROR
QTextStream fs (&f);
QString line;
while (! fs.eof()) {
line = fs.readLine();
SubUnit* s = SubUnit::makeSubUnit(line);
elstable->replace(s->getName(), s);
}
f.close();
}
/**
- * Save the element definitions file.
- */
-void KMolCalc::writeElstable() {
- QFile f(mwfile);
- if (! f.open(IO_WriteOnly)) return; //ERROR
- QTextStream fs (&f);
- QString line;
- QDictIterator<SubUnit> it(*elstable);
- while (it.current()) {
- it.current()->writeOut(line);
- fs << line << endl;
- ++it;
- }
- f.close();
-}
-
-/**
* Remove a group or element definition from ELSTABLE.
*/
void KMolCalc::undefineGroup (const QString& name) {
elstable->remove (name);
}
/**
* Add a new element name - atomic weight record to the ELSTABLE hashtable. Assumes
* NAME has valid syntax.
*/
void KMolCalc::defineElement (const QString& name, double weight) {