- Small improvements in logging and rc file format (comments lines and debug parameter with 0,1,2 values);
void dEditDialog::init()
{
delete statusBar();
+ docId = 0;
// eModule->setInterpreter(new QSInterpreter());
// fd = new aFormDesigner();
}
eFormFile->setText( QString("inputform_")+QString::number(item->id)+QString(".ui"));
setCaption( tr("Form:") + eName->text() );
parentClass = md->objClass( md->parent ( md->parent( obj ) ) );
+ docId = md->id(md->parent(md->parent( obj )));
if ( parentClass == md_document ) {
// cbFormMode->insertItem(QObject::tr("Document"));
}
void dEditDialog::EditForm()
{
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ if (widget->name() == QString("ananas-designer_mainwindow") )
+ {
+ connect( this, SIGNAL( setId( qulonglong * ) ), widget, SLOT( setId( qulonglong * ) ));
+ emit ( setId( &docId ));
+ }
+ }
aCfg *md = item->md;
aCfgItem obj = item->obj, o;
QFile f( eFormFile->text() );
// char* arg;
// int rc;
- aLog::print(aLog::Debug,tr("dEditDialog edit form"));
//MainForm *mw = (MainForm*) topLevelWidget();
//printf("end getting pointer to Main form\n");
QStringList env;
-int dEditDialog::getDocId()
+qulonglong dEditDialog::getDocId()
{
return docId;
}
dEditDialog(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = Qt::WType_TopLevel);
~dEditDialog();
- int docId;
+ qulonglong docId;
aAliasEditor *al;
aFormDesigner *fd;
aListViewItem *item;
- virtual int getDocId();
+ virtual qulonglong getDocId();
public slots:
virtual void init();
virtual void EditModule();
virtual void updateMD();
+signals:
+ void setId(qulonglong* id);
protected slots:
virtual void languageChange();
#include "formdesigner.h"
MainForm *mainform = 0;
-aWindowsList *mainformwl = 0;
-QWorkspace *mainformws = 0;
+// aWindowsList *mainformwl = 0;
+// QWorkspace *mainformws = 0;
//QApplication *application = 0;
QTranslator *translator = 0, tr_app(0), tr_lib(0), tr_plugins(0);
aFormDesigner *formdesigner = 0;
rcfile="",
username="",
userpassword="";
-
+aDatabase* database= NULL;
+aCfgRc rc;
int setTranslator(QString langdir, QString lang)
{
return 0;
}
-
int main( int argc, char ** argv )
{
AApplication app ( argc, argv, AApplication::Designer );
- MainForm *w = new MainForm();
+ MainForm *appWindow = new MainForm();
//#ifndef _Windows
- QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF8") );
+ QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF8") );
//#endif
// Для QSettings
app.setOrganizationName("ananasgroup");
- app.setApplicationName("ananas");
+ app.setApplicationName("ananas");
- mainform = w;
- mainformws = mainform->ws;
- mainformwl = mainform->wl;
+ mainform = appWindow;
+ // mainformws = mainform->ws;
+ // mainformwl = mainform->wl;
// application = &app;
// dSelectDB dselectdb;
- int rc;
QPixmap pixmap;
+ QString configWorkDir = QDir::homeDirPath()+"./ananas";
+ QString logLevel = "0";
if ( parseCommandLine( &app ) ) return 1;
+ if ( !rcfile.isEmpty() )
+ {
+ rc.read( rcfile );
+ configWorkDir = rc.value("workdir", configWorkDir);
+ logLevel = rc.value("debug", "0");
+
+ }
+ if (logLevel == "0" || logLevel == "1" || logLevel == "2")
+ aLog::init( configWorkDir+"/ananas.log", logLevel.toInt() );
+ else
+ aLog::init( configWorkDir+"/ananas.log", 0 );
+
qApp->installTranslator( &tr_lib );
qApp->installTranslator( &tr_plugins );
qApp->installTranslator( &tr_app );
qApp->addLibraryPath( qApp->applicationDirPath() );
#else
pixmap = QPixmap( "/usr/share/ananas/designer/locale/designer-splash-"+lang+".png" );
- qApp->addLibraryPath( "/usr/lib/ananas/" );
- qApp->addLibraryPath( "/usr/lib/ananas/designer/" );
+ qApp->addLibraryPath( "/usr/lib/ananas/" );
+ qApp->addLibraryPath( "/usr/lib/ananas/designer/" );
// qApp->setLibraryPaths( QStringList() <<"/usr/lib/ananas/" );
#endif
foreach (QString path, app.libraryPaths())
- printf("%s\n", path.toUtf8().data());
+ aLog::debug(QString("libraryPaths list item " ) + path);
if ( pixmap.isNull() )
pixmap = QPixmap( ":/images/designer-splash-en.png" );
QSplashScreen *splash = new QSplashScreen( pixmap );
- if ( ananas_login( rcfile, username, userpassword, 0, AApplication::Designer ) ){
- splash->show();
- splash->message( QObject::tr("Init application"), Qt::AlignBottom, Qt::white );
- w->rcfile = rcfile;
- qApp->setMainWidget( w );
- splash->message( QObject::tr("Init forms designer"), Qt::AlignBottom, Qt::white );
- formdesigner = new aFormDesigner();
-
- //--formdesigner->reparent( mainformws, 0, QPoint( 5, 5 ), false );
-// mainformws->addWindow(formdesigner);
- formdesigner->setCaption( QObject::tr("Dialog forms designer") );
- formdesigner->hide();
- w->show();
- splash->clear();
- splash->finish( w );
- delete splash;
- qApp->connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );
- mainform->configOpen();
-// QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF8") );
-
- rc = app.exec();
- if( w ) delete w;
- w=0;
- aLog::close();
- ananas_logout();
- return rc;
+
+
+ dSelectDB dialogDBSelect;
+
+ if ( rcfile.isEmpty() )
+ {
+ if (dialogDBSelect.exec()==QDialog::Accepted) rcfile = dialogDBSelect.rcfile;
}
+ if ( !rcfile.isEmpty() )
+ {
+ if ( !database ) database = aDatabase::database();
+ if ( !database->init( rcfile ) )
+ {
+ aLog::error("Unable to use rcfile " + rcfile);
+ return 1;
+ }
+ }
+ else
+ {
+ aLog::debug("No rcfile selected or available?");
+ return 0;
+ }
+
+ splash->show();
+ splash->message( QObject::tr("Init application"), Qt::AlignBottom, Qt::white );
+ appWindow->rcfile = rcfile;
+ appWindow->md = &database->cfg;
+ qApp->setMainWidget( appWindow );
+ splash->message( QObject::tr("Init forms designer"), Qt::AlignBottom, Qt::white );
+ formdesigner = new aFormDesigner();
+
+ //--formdesigner->reparent( mainformws, 0, QPoint( 5, 5 ), false );
+ // mainformws->addWindow(formdesigner);
+ formdesigner->setCaption( QObject::tr("Dialog forms designer") );
+ formdesigner->hide();
+ appWindow->show();
+ splash->clear();
+ splash->finish( appWindow );
+ delete splash;
+ qApp->connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );
+ // mainform->configOpen();
+ appWindow->configOpen();
+ // QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF8") );
+
+ int res = app.exec();
+ // if( appWindow ) delete appWindow;
+ // appWindow=0;
+ // aLog::close();
+ // ananas_logout();
+ // return rc;
+
aLog::close();
- return 0;
+ return res;
}
TBToolbar->setShown( FALSE );
tbTabs->setShown( FALSE );
lastTabId = 0;
+ lastFormId = 0;
configSaveAction->setVisible( FALSE );
}
*md = &cf->cfg;
}
+aCfg* MainForm::getMetadata()
+{
+ return md;
+}
+
/*!
Get current configuration form
*/
return ws->activeWindow();
}
+void MainForm::setId( qulonglong* id )
+{
+ lastFormId= *id;
+}
-int MainForm::getId()
+void
+MainForm::getId(qulonglong* objId)
{
- return lastFormId;
+ *objId = lastFormId;
}
CfgForm *cfgform;
QString rcfile;
aCfg *md;
- int lastFormId;
+ qulonglong lastFormId;
int lastTabId;
aWindowsList *wl;
//--QSettings designer_settings;
virtual void fileNew();
virtual void connectSignals( CfgForm * cf );
virtual void getMd( aCfg * * md );
- virtual int getId();
+ virtual aCfg* getMetadata();
+ virtual void setId(qulonglong* id);
+ virtual void getId(qulonglong* id);
virtual void addTab( int uid, const QString & winName );
// -- Help for add to workspace
virtual void addTab(QWidget* window) {
stream.setEncoding(Q3TextStream::UnicodeUTF8);
while ( !stream.eof() ) {
line = stream.readLine(); // line of text excluding '\n'
+ if ( line.trimmed().startsWith("#") ) // skip comments line
+ continue;
k = line.section("=",0,0);
v = line.section("=",1,100); if ( v.isNull() ) v = "";
values.insert( k, new QString( v ) );
#include <qdir.h>
#include <qdatetime.h>
#include "aservice.h"
+#include <iostream>
QString aLog::logName = "";
int aLog::logLevel = aLog::Debug;
-QFile aLog::f;
+QFile aLog::logFileRef;
bool aLog::msg_was_show = false;
+bool aLog::initialized = false;
+bool aLog::echoRequired = true;
//const int aLog::Error = 0;
//const int aLog::Info = 1;
//const int aLog::Debug = 2;
+void aLog::debug( QString const &message)
+{
+ aLog::print(aLog::Debug, message);
+}
+
+void aLog::error( QString const &message)
+{
+ aLog::print(aLog::Error, message);
+}
+
+void aLog::info( QString const &message)
+{
+ aLog::print(aLog::Info, message);
+}
/*!
*\~english
- * Writes text to log, if /a status less init status.
+ * Writes text to log, if a status less init status.
* \param status - message status ( aLog::Error, aLog::Info, aLog::Debug )
* \param text - message
*\~russian
const QString &text)
{
QString st;
-// switch(status)
-// {
-// case aLog::Error:
- if(status == aLog::Error) st = "ERROR";
-// break;
-// case aLog::Info:
- else if(status == aLog::Info) st = "INFO";
-// break;
-// default:
- else st = "DEBUG";
-// break;
-// }
+ if(status == aLog::Error) st = "ERROR";
+ else if(status == aLog::Info) st = "INFO";
+ else st = "DEBUG";
if(status<=logLevel)
{
- QString endline;
-
+ QString endline;
+
#ifdef Q_OS_WIN32
- endline = "\r\n";
+ endline = "\r\n";
#else
- endline = "\n";
+ endline = "\n";
#endif
const QString toWrite = QString("%1 %2 %3%4")\
- .arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace('T',' '))\
- .arg(st)\
- .arg(text)\
- .arg(endline);
+ .arg(QDateTime::currentDateTime().toString(Qt::ISODate).replace('T',' '))\
+ .arg(st)\
+ .arg(text)\
+ .arg(endline);
aLog::printr(toWrite);
}
}
void
aLog::printr( const QString &toWrite)
{
- if(aLog::f.handle () !=-1)
+ if(aLog::logFileRef.handle() !=-1 && aLog::initialized && aLog::logFileRef.isOpen())
{
- aLog::f.writeBlock((const char*)toWrite.local8Bit(),strlen((const char*)toWrite.local8Bit()));
- aLog::f.flush();
+ aLog::logFileRef.writeBlock((const char*)toWrite.local8Bit(),strlen((const char*)toWrite.local8Bit()));
+ aLog::logFileRef.flush();
+ if (aLog::echoRequired)
+ {
+ std::cout << toWrite.toStdString();
+ }
}
else
{
if(!aLog::msg_was_show)
{
- printf("Log system not initialized!\n");
+ std::cout << "Log system not initialized!" << std::endl <<"Writing to stdout" << std::endl;
aLog::msg_was_show = true;
}
+ std::cout << toWrite.toStdString();
}
}
* \param status - \~english showing status \~russian статус скрытия сообщений. Все сообщения, имеющие больший статус, не попадут в лог ( ERROR= 0, INFO= 1, DEBUG= 2 ). Значение по умолчанию DEBUG \~
*/
void
-aLog::init(const QString &log_name, int show_up)
+aLog::init(const QString &log_name, int show_up, bool echoToConsole)
{
+ if ( aLog::initialized )
+ return;
bool ok;
QString log;
+ aLog::echoRequired = echoToConsole;
if(log_name =="" || logName==QString::null)
{
log = aService::readConfigVariable("log", &ok);
- if(!ok) log = QDir::homeDirPath()+"/.ananas/ananas.log";
+ if(!ok )
+ {
+ if (createDotAnanasDir())
+ {
+ log = QDir::homeDirPath()+"/.ananas/ananas.log";
+ }
+ else
+ {
+ if (aLog::logLevel == aLog::Debug)
+ {
+ std::cout << "Log system not initialized!" << std::endl;
+ }
+ return;
+ }
+ }
}
else
{
aLog::logName = log;
- if (aLog::f.isOpen()) f.close();
- aLog::f.setName(getLogName());
- aLog::f.open( IO_WriteOnly | IO_Append );
-
+ if (aLog::logFileRef.isOpen()) aLog::logFileRef.close();
+ aLog::logFileRef.setName(getLogName());
+ aLog::initialized = aLog::logFileRef.open( IO_WriteOnly | IO_Append );
+ if (aLog::initialized && aLog::logLevel == aLog::Debug)
+ {
+ std::cout << "aLog::init(), logFile opened" << std::endl;
+ }
}
QString
void
aLog::close()
{
- aLog::f.close();
+ if (aLog::logFileRef.isOpen())
+ {
+ aLog::logFileRef.close();
+ if (aLog::logLevel == aLog::Debug)
+ {
+ std::cout << "aLog::close(), logFile Closed" << std::endl;
+ }
+ }
}
+bool
+aLog::createDotAnanasDir()
+{
+ QDir dir(QDir::homeDirPath()+"/.ananas");
+ if (dir.exists()) return true;
+ return dir.mkpath(".");
+}
#ifndef ALOG_H
#define ALOG_H
-//#include "ananas.h"
#include "ananasglobal.h"
#include <qstring.h>
#include <qfile.h>
-// for bcc32.exe compatibility
-// in file wingdi.h
-// #define ERROR 0
-
-//#ifdef Q_OS_WIN32
-//#define ERROR IRROR
-//#endif
-
/*!
* \~english
* Class contain static functions for log system
{
public:
enum MessageType { Error, Info, Debug };
-// enum status {
- /*!
- * \~english Error
- * \~russian Сообщение об ошибке
- * \~
- */
-/*
-#ifdef Q_OS_WIN32
- static const int IRROR;//,
-#else
- static const int ERROR;
-#endif
-*/ /*!
- * \~english Info
- * \~russian Информационное сообщение
- * \~
- */
-// static const int INFO;//,
- /*!
- * \~english Info
- * \~russian Отладочное сообщение
- * \~
- */
-// static const int DEBUG;// };
static void print( int status, const QString &text);
+ static void debug( QString const &text);
+ static void error( QString const &message);
+ static void info( QString const &text);
static void printr( const QString &text);
- static void init( const QString &logname="", int loglevel=0);
+ static void init( const QString &logname="", int loglevel=0, bool echoToConsole = true);
static void close();
static QString getLogName();
private:
aLog();
+ static bool createDotAnanasDir();
static QString logName;
static int logLevel;
- static QFile f;
+ static QFile logFileRef;
static bool msg_was_show;
-
+ static bool initialized;
+ static bool echoRequired;
};
#endif// ALOG_H
void dSelectDB::init()
{
- aLog::init("ananas.log", aLog::Debug);
createMenu();
progressBar1->hide();
QString fname;
#include "wdbtable.h"
#include "aform.h"
#include "alog.h"
-
+#include <qapplication.h>
/*!
*\en
emit( getData( object ) );
}
-
-
/*!
*\en
* Return toplevel metadata configuration.
aWidget::getMd()
{
aCfg *md = 0;
- QWidget *mw = topLevelWidget();
- if (mw->name() == QString("ananas-designer_mainwindow") )
- {
- connect( this, SIGNAL( getMd( aCfg ** ) ), mw, SLOT( getMd( aCfg ** ) ));
- emit ( getMd( &md ) );
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ if (widget->name() == QString("ananas-designer_mainwindow") )
+ {
+ connect( this, SIGNAL( getMd( aCfg ** ) ), widget, SLOT( getMd( aCfg ** ) ));
+ emit ( getMd( &md ) );
+ }
}
return md;
}
#include "edbfield.h"
#include "wdbfield.h"
#include "addfdialog.h"
-//--#include "mainform.h"
+#include <alog.h>
id = aWidget::parentContainer(this)->getId();
head = md->find(id);
}
+ else
+ {
+ aLog::debug("wDBField::init(), Can't get metadata or metaobject Id");
+ }
}
#include "wdbfield_taskmenu.h"
#include "wdbfield.h"
-
+#include <alog.h>
wDBFieldPlugin::wDBFieldPlugin(QObject *parent)
: QObject(parent), m_initialized(false)
Q_TYPEID(QDesignerTaskMenuExtension));
m_initialized = true;
- printf("dbfield inited\n");
+ aLog::debug("wDBFieldPlugin::initialize, dbfield initialized\n");
}
QWidget *wDBFieldPlugin::createWidget(QWidget *parent)
objtype = "";
defColWidth = 100; //default column width
tableInd = -1;
+ doc_id = 0;
inEditMode = false;
searchWidget = 0;
searchMode = false;
* \~
*/
qulonglong
-wDBTable::getId() const
+wDBTable::getId()
{
+ if (doc_id == 0)
+ {
+ foreach (QWidget *widget, QApplication::topLevelWidgets())
+ {
+ if (widget->name() == QString("ananas-designer_mainwindow") )
+ {
+ connect( this, SIGNAL( getId( qulonglong * ) ), widget, SLOT( getId( qulonglong * ) ));
+ emit ( getId( &doc_id ) );
+ }
+ }
+ }
return doc_id;
}
cur=0;
}
+/*!
+ *\en
+ * Return toplevel metadata configuration.
+ *\_en
+ *\ru
+ * Возвращает объект конфигурации для виджета верхнего уровня.
+ *\_ru
+ */
+aCfg*
+wDBTable::getMd()
+{
+ foreach (QWidget *widget, QApplication::topLevelWidgets())
+ {
+ if (widget->name() == QString("ananas-designer_mainwindow") )
+ {
+ connect( this, SIGNAL( getMd( aCfg ** ) ), widget, SLOT( getMd( aCfg ** ) ));
+ emit ( getMd( &md ) );
+ }
+ }
+ return md;
+}
+
/*!
void
wDBTable::init()// aDatabase *adb )
{
- int id=0;
+ qulonglong id=0;
aCfgItem o, o_table;
aCfgItem mditem, docitem;
// set up pixmap for calculated fields
cur = new Q3SqlCursor("cur",false);
- md = aWidget::parentContainer(this)->getMd();
- if ( md )
+ md = getMd();
+ id = getId();
+ aLog::debug("wDBTable::init(), metadata object id="+QString::number(id));
+ if ( md && id != 0)
{
- id = aWidget::parentContainer(this)->getId();
o = md->find(id);
QString objClass = md->objClass(o);
if(objClass==md_document)
}
else
{
+ aLog::debug("wDBTable::init(), Can't get metadata or metaobject Id");
// verticalHeader()->hide();
// printf("name engin\n");
}
QStringList getDefHeaders() const;
QStringList getColWidth() const;
QStringList getDefIdList() const;
- qulonglong getId() const;
+ qulonglong getId();
int getTblInd() const;
bool getOpenEditor() const;
int getDefColWidth() const;
void setContainerType( QString name) { container_type = name; };
QPixmap systemIcon();
virtual int Select( ANANAS_UID db_uid );
+ aCfg* getMd();
public slots:
Q3ValueList<int> getBindList();
void setWFieldEditor();
*/
void viewRequest();
// end
+ void getMd( aCfg ** );
+ void getId( qulonglong * );
private slots:
//void select( Q_ULLONG group );