Esempio n. 1
0
//
// Thread pool processes
//
bool TreeLeaf::exec()
{
    QMutexLocker locker(&m_RunLocker);
    //
    switch(getObjectStatus())
    {
    case AbstractDatabaseObject::OBJECT_OK:
        return true;
    case AbstractDatabaseObject::OBJECT_NAME_UPDATING:
        {
            bool b_update_name = updateName_DB();
            if (b_update_name)
            {
                QString str_message = QString("(id = %1) new name='%2'").arg(m_iID).arg(this->text(0));
                Logger::getInstance().logIt(en_LOG_UPDATE_NODE, str_message );
            };
        };
        break;
    case AbstractDatabaseObject::OBJECT_TREE_ID_UPDATING:
        updateTreeID_DB();
        break;
    case AbstractDatabaseObject::OBJECT_DESCRIPTOR_UPDATING:
        {
            bool b_update = updateDescriptor_DB();
            if (b_update)
            {
                QString str_message = QString("(id = %1) name='%2' updated").arg(m_iID).arg(this->text(0));
                Logger::getInstance().logIt(en_LOG_DESCRIPTOR_NODE, str_message );
            };
        };
        break;
    case AbstractDatabaseObject::OBJECT_DELETING:
        setObjectStatus(OBJECT_DELETED);
        IconManager::getInstance().minusInUse(m_iIconID);
        deleteAllAttachments();
        setActiveStatus_DB(false);
        setItemColor();
        notifyAboutAttachmentUpdate(true, tr(""));
        {
            QString str_message = QString("(id = %1) name='%2'").arg(m_iID).arg(this->text(0));
            Logger::getInstance().logIt(en_LOG_DELETE_NODE, str_message );
        }
        return true;
    case AbstractDatabaseObject::OBJECT_ATTACHMENT_INSERT: //do nothing
        return true;
    default:
/*
#ifdef QT_DEBUG
        DB_OBJECT_STATUS status = getObjectStatus(); //just for check under debugger
#endif
*/
        Q_ASSERT( FALSE );
        return false;
    };
    //
    setObjectStatus(AbstractDatabaseObject::OBJECT_OK);
    return true;
    //
//    m_RunLocker.unlock();
}
Esempio n. 2
0
bool  TreeLeaf::restoreSubtree  ()
{
    if ( isPossibleToRestoreNode() == false )
        return false;
    //
    setActiveStatus_DB(true);
    //
    setObjectStatus(OBJECT_OK);
    //
    QString str_msg;
    str_msg = "node ";
    str_msg += this->text(0);
    str_msg += " restored.";
    //
    placeStatusBarMsg(str_msg);
    //
    setItemColor();
    //restore all attachments
    restoreAllAttachments();
    //
    for (int i = 0; i < this->childCount(); i++)
    {
        TreeLeaf* ptr_child_leaf =  (TreeLeaf*) this->child(i);
        if (ptr_child_leaf)
            ptr_child_leaf->restoreSubtree();
    };
    //
    return true;
};
Esempio n. 3
0
void TreeLeaf::setNewTreeID(unsigned int ui_tree_id)
{
    if (m_iDBTreeID == ui_tree_id)
        return;  //do nothing, it is the same tree
    //
    m_iDBTreeID = ui_tree_id;
    //
    setObjectStatus(OBJECT_TREE_ID_UPDATING);
    //
    //QThreadPool::globalInstance()->start(this);
    AdvThreadPool::getInstance().execute(this);
    //
    for (int i = 0; i < this->childCount(); i++)
    {
        TreeLeaf* ptr_child_leaf =  (TreeLeaf*) this->child(i);
        if (ptr_child_leaf)
            ptr_child_leaf->setNewTreeID(ui_tree_id);
    };
}
Esempio n. 4
0
bool TreeLeaf::rename_it (const QString &str_name)
{
    Q_UNUSED(str_name);
    //
    QString str_new_name = this->text(0);
    //
    if (str_new_name.length() == 0)
        return false;
    //
    if (m_strDatabaseNodeName == str_new_name)
        return false;
    //
    setObjectStatus(OBJECT_NAME_UPDATING);
    //
    //QThreadPool::globalInstance()->start(this);
    AdvThreadPool::getInstance().execute(this);
    //
    return true;
}
Esempio n. 5
0
bool TreeLeaf::restoreObject()
{
    if ( isPossibleToRestoreNode() == false )
        return false;
    //
    QString str_msg;
    //
    setActiveStatus_DB(true);
    //
    setObjectStatus(OBJECT_OK);
    //
    str_msg = "node ";
    str_msg += this->text(0);
    str_msg += " restored.";
    //
    placeStatusBarMsg(str_msg);
    //
    setItemColor();
    //
    return true;
};
Esempio n. 6
0
void  TreeLeaf::setDescriptor  (const QString& str_descriptor, bool b_is_html)
{
    if ( true == b_is_html )
    {
        if (str_descriptor == m_docDescriptor.toHtml())
            return;
        //bug in Qt, this code is NOT useless.
        m_docDescriptor.setHtml(str_descriptor);
        QString str_original_html = m_docDescriptor.toHtml();
        //
    }else //it is text - file (using for import only right now
    {
        if ( str_descriptor == m_docDescriptor.toPlainText() )
            return;
        //
        m_docDescriptor.setPlainText(str_descriptor);
    };
    //
    setObjectStatus(OBJECT_DESCRIPTOR_UPDATING);
    //
    //QThreadPool::globalInstance()->start(this);
    AdvThreadPool::getInstance().execute(this);
}
Esempio n. 7
0
bool TreeLeaf::delete_it(bool b_silence)
{
    if ( false == isPossibleToDeleteNode( b_silence, m_bForceDelete) )
        return false;
    //
    //already deleted, nothing to delete
    //
    if (getObjectStatus() == OBJECT_DELETED)
        return true;
    //
    int ret = QMessageBox::Ok;
    //
    if ( this->childCount() > 0 )
    {
        //
        if (false == b_silence)
        {
            QString str_msg = "You will delete all child nodes also.";
            QMessageBox box;
            box.setInformativeText(str_msg);
            box.setStandardButtons(QMessageBox::Ok| QMessageBox::Cancel);
            box.setDefaultButton(QMessageBox::Ok);
            ret = box.exec();
        };
        //
    };
    //
    if (ret == QMessageBox::Ok)
    {
        setObjectStatus( OBJECT_DELETING );
        //
/*
        //delete all attachments also
        deleteAllAttachments();
        //
        //TODO: push it into thread pool?
        //
        setActiveStatus_DB(false);
*/
//        QThreadPool::globalInstance()->start(this);
        AdvThreadPool::getInstance().execute (this);
        //
        for (int i = 0; i < this->childCount(); i++)
        {
            TreeLeaf* ptr_child_leaf =  (TreeLeaf*) this->child(i);
            if (ptr_child_leaf)
                ptr_child_leaf->delete_it(true);
        };
    }else
    {
        return false;
    };
    //
    QString str_msg1 = tr("node ");
    str_msg1 += this->text(0);
    str_msg1 += tr(" deleted.");
    //
    placeStatusBarMsg(str_msg1);
    //
    return true;
}
int monitorFileControl(FILE * logf, struct SCRIPT * script, struct TYPING * types,
				unsigned long location, struct LINE * line){	   
	char tokens[TOKENMAXNB][TOKENSIZE]; char exp[TOKENSIZE]; int next = 1;
	static char driveobj[TOKENSIZE]; 
	static int drives = 0; static int driveset;
	int i, obj1, nbtokens, unknown = -1;
	struct LINE combined; static int combinnb = 45;
	char combinid[TOKENSIZE]; char * combinline;

	struct MANAG_ENTRY * localmanagers = accessManagers(script,location); 
	nbtokens = decomposeLine(line->line,(char*)tokens,TOKENMAXNB,TOKENSIZE);
	for(i=0;i<nbtokens;i++){
		
		unknown = isUnknownManager(&script->managers,tokens[i]);
		//File system manager
		if((isFileManager(&script->managers,tokens[i])>-1)
			|| (isFileManager(localmanagers,tokens[i])>-1)
			|| (unknown>-1)){
			
			//Open command
			if(!strcasecmp(tokens[i+1],OPENF1)//file
				|| !strcasecmp(tokens[i+1],OPENF2)
					|| !strcasecmp(tokens[i+1],OPENF3)){
				line->type = SYSCALL;
				processExpression(logf,script,types,location,
										   line,i+2,OBJ_FILE,exp,&next);
				obj1 = updateTypesAfterSysCall(types,exp,
													NULL,OBJ_FILE,OBJ_EXIST);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);

				//Checks combined call
				combinline = strstr(line->line,tokens[next]);
				if((nbtokens-2>=next)&&combinline){
					char * found;
					combinline--;
					found = strchr(combinline,'.');
					if(!found){
						if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
						if(unknown>1) //learn manager class
							addManagerObject(&script->managers,TFSO,tokens[i]);
						return 1;
					}
					sprintf_s(combinid,TOKENSIZE,"INT%08X",combinnb); combinnb++;
					addObjectReference(types,obj1,combinid);
					if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in"))){
						sprintf_s(combined.line,LINE_LENGTH,"%s = %s.%s",
							    tokens[i-2],combinid,found);
					}else{
						sprintf_s(combined.line,LINE_LENGTH,"%s.%s",combinid,found);
					}
					if(!monitorFileIO(logf,script,types,location,&combined)){
						removeObjectReference(types,obj1,combinid);
						if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
					}
				}else{
					if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
				}
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;

			//File existence command
			}else if(!strcasecmp(tokens[i+1],OPENFT)){
				line->type = SYSCALL;
				processExpression(logf,script,types,location,
										   line,i+2,OBJ_FILE,exp,NULL);
				obj1 = updateTypesAfterSysCall(types,exp,
													NULL,OBJ_FILE,OBJ_CREATED);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;

			//Drive commands
			}else if(!strcasecmp(tokens[i+1],OPEND1)){
			    line->type = SYSCALL;
				obj1 = updateTypesAfterSysCall(types,COM_DRIVE,
													tokens[i-2],OBJ_DRIVE,OBJ_EXIST);
				sprintf_s(types->objects[obj1].ObjectName, NAME_MAX_LENGTH,
													"Drive(ref:%s)",tokens[i-2]);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;
			}else if(!strcasecmp(tokens[i+1],OPEND2)){
				if((i+2<nbtokens&&!strcasecmp(tokens[i+2],"Item"))
					||(i-2>=0&&!strcasecmp(tokens[i-1],"In"))){
					line->type = SYSCALL;
					obj1 = updateTypesAfterSysCall(types,COM_DRIVE,
													tokens[i-2],OBJ_DRIVE,OBJ_EXIST);
					sprintf_s(types->objects[obj1].ObjectName, NAME_MAX_LENGTH,
													"Drive(ref:%s)",tokens[i-2]);
					printLogEntry(logf, types, OP_OPEN, obj1, 0);
				}else if(i-2>=0&&tokens[i-1][0]=='='){
					drives = 1;
					strcpy_s(driveobj,TOKENSIZE,tokens[i-2]);
					line->type = SYSCALL;
				}else{
					line->type = SYSCALL;
				}
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;
			}//if open
		
			//Creation command
			if(!strcasecmp(tokens[i+1],CREATEF2)
				|| !strcasecmp(tokens[i+1],CREATEF3)){
				line->type = SYSCALL;
				processExpression(logf,script,types,location,
					                       line,i+2,OBJ_FILE,exp,&next);
				obj1 = updateTypesAfterSysCall(types,exp,
													NULL,OBJ_FILE,OBJ_CREATED);
				printLogEntry(logf, types, OP_CREA, obj1, 0);

				//Checks combined call
				combinline = strstr(line->line,tokens[next]);
				if((nbtokens-2>=next)&&combinline){
					char * found = strchr(combinline,'.');
					if(!found){
						if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
						if(unknown>1) //learn manager class
							addManagerObject(&script->managers,TFSO,tokens[i]);
						return 1;
					}
					sprintf_s(combinid,TOKENSIZE,"INT%08X",combinnb); combinnb++;
					addObjectReference(types,obj1,combinid);
					if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in"))){
						sprintf_s(combined.line,LINE_LENGTH,"%s = %s.%s",tokens[i-2],combinid,found);
					}else{
						sprintf_s(combined.line,LINE_LENGTH,"%s.%s",combinid,found);
					}
					if(!monitorFileIO(logf,script,types,location,&combined)){
						removeObjectReference(types,obj1,combinid);
						if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
					}
				}else{
					if(i>=2&&(tokens[i-1][0]=='='||!strcasecmp(tokens[i-1],"in")))
							addObjectReference(types,obj1,tokens[i-2]);
				}
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;
			}//if creation
				
			//Delete command
			if(!strcasecmp(tokens[i+1],DELETEF1)
				|| !strcasecmp(tokens[i+1],DELETEF2)){
				line->type = SYSCALL;
				processExpression(logf,script,types,location,
					                       line,i+2,OBJ_FILE,exp,NULL);
				obj1 = updateTypesAfterSysCall(types,exp,
													tokens[i-2],OBJ_FILE,OBJ_EXIST);
				printLogEntry(logf, types, OP_DEL, obj1, 0);
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TFSO,tokens[i]);
				return 1;
			}//if delete
		
		}//if file system manager

		//Drive set object 
		if(drives && !strcasecmp(driveobj,tokens[i])){
			if((i+1<nbtokens && (!strcasecmp(tokens[i+1],"Item")||
				!strcasecmp(tokens[i+1],"Files")))|| !strcasecmp(tokens[i-1],"in")){
				line->type = SYSCALL;
				obj1 = updateTypesAfterSysCall(types,COM_DRIVE,
											tokens[i-2],OBJ_DRIVE,OBJ_EXIST);
				sprintf_s(types->objects[obj1].ObjectName, NAME_MAX_LENGTH,
													"Drive(ref:%s)",tokens[i-2]);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);
				return 1;
			}
		}//if drive set

		//Document object
		if((nbtokens-i>2) && !strcasecmp(tokens[i],"Document")){
			if(!strcasecmp(tokens[i+1],"Body")&&!strcasecmp(tokens[i+2],OPENDOC)){
				line->type = SYSCALL;
				obj1 = updateTypesAfterSysCall(types,HTM_DOC,
											NULL,OBJ_FILE,OBJ_EXIST);
				if(i>=2) addObjectReference(types,obj1,tokens[i-2]);
				setObjectStatus(types,obj1,OBJ_EXIST);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);
				return 1;
			}
		}

		//Shell manager
		if((isShellManager(&script->managers,tokens[i])>-1)
			|| (isShellManager(localmanagers,tokens[i])>-1)){
			
			//Open command
			if(!strcasecmp(tokens[i+1],OPENRUN)){
				line->type = SYSCALL;
				processExpression(logf,script,types,location,
										   line,i+2,OBJ_FILE,exp,&next);
				obj1 = updateTypesAfterSysCall(types,exp,
													NULL,OBJ_FILE,OBJ_EXIST);
				printLogEntry(logf, types, OP_OPEN, obj1, 0);
				if(unknown>1) //learn manager class
					addManagerObject(&script->managers,TSHELL,tokens[i]);
				return 1;
			}
		}
	}//for
	return 0;
}