示例#1
0
文件: io.c 项目: ainomelody/RentBook
void loadFromFile(char *filename)
{
	FILE *fp;
	BookType *node, *tail = NULL;
	
	fp = fopen(filename, "rb");
	
	if (fp == NULL)
	{
		char text[100];
		
		sprintf(text, "无法读取文件 %s\0", filename);
		messageBox(mainWindow, GTK_MESSAGE_ERROR, "错误", text);
		return;
	}
	
	freeTypeList(head);
	head = NULL;
	
	statusShow("正在读取...");
	
	node = g_malloc(sizeof(BookType));
	fread(node, sizeof(BookType), 1, fp);
	head = tail = node;
	node->prev = NULL;
	
	if (feof(fp))
	{
		statusShow("读取失败");
		g_free(node);
		head = NULL;
		return;
	}
	
	if (node->bookList != NULL)
		loadBookInfo(&node->bookList, fp);
	
	while (node->next != NULL && !feof(fp))
	{
		node = g_malloc(sizeof(BookType));
		fread(node, sizeof(BookType), 1, fp);
		tail->next = node;
		node->prev = tail;
		tail = node;
		
		if (node->bookList != NULL)
			loadBookInfo(&node->bookList, fp);
	}
	
	statusShow("完成");
	
}
示例#2
0
void MainFrm::rulesInitialized(bool bReady)
{
    if (!bReady)
        displayError(tr("Could not initialize rules!"),true);
    else
        statusShow(tr("Rules correctly initialized!"));
}
示例#3
0
void MainFrm::newTabs()
{
    qApp->setOverrideCursor( QCursor(Qt::BusyCursor ) );
    statusShow(tr("Wait..."));

        if (pFrmReports->isVisible())
            closeSecondaryFrm(pFrmReports);

        resetTabs();

        if (sSample!=0) {delete sSample; sSample=0;}
        sSample=new Sample;
        initTabs();

    statusShow(tr("Project successfully initialized."));
    qApp->setOverrideCursor( QCursor(Qt::ArrowCursor ) );
}
示例#4
0
文件: io.c 项目: ainomelody/RentBook
void saveToFile(char *filename)
{
	FILE *fp;
	BookType *typeList;
	BookInfo *bookList;
	RentInfo *rentList;
	
	fp = fopen(filename, "wb");
	if (fp == NULL)							//对话框提示
	{
		char text[100];
		
		sprintf(text, "无法写入文件 %s\0", filename);
		messageBox(mainWindow, GTK_MESSAGE_ERROR, "错误", text);
										
		return;
	}
	
	statusShow("正在保存...");
	
	typeList = head;
	while (typeList != NULL)
	{
		fwrite(typeList, sizeof(BookType), 1, fp);
		bookList = typeList->bookList;
		
		while (bookList != NULL)
		{
			fwrite(bookList, sizeof(BookInfo), 1, fp);
			rentList = bookList->rentList;
			
			while (rentList != NULL)
			{
				fwrite(rentList, sizeof(RentInfo), 1, fp);
				rentList = rentList->next;
			}
			
			bookList = bookList->next;
		}
		
		typeList = typeList->next;
	}
	fclose(fp);
	
	statusShow("完成");
}
示例#5
0
void MainFrm::RebuildIndexes()
{
    //Rebuilding indexes on a separate thread...
    RebuildIndexesThread t;

    connect(&t, SIGNAL(showStatus(QString)), this,
        SLOT(statusShow(QString)));

    connect(&t, SIGNAL(showError(QString,bool)), this,
        SLOT(displayError(QString,bool)));

    t.run();
}
示例#6
0
void MainFrm::initRules()
{
    if (ruleCheckerPtr!=0) {delete ruleCheckerPtr; ruleCheckerPtr=0;}

    ruleCheckerPtr=new RuleChecker();

    connect(ruleCheckerPtr, SIGNAL(showStatus(QString)), this,
        SLOT(statusShow(QString)));

    connect(ruleCheckerPtr, SIGNAL(showError(QString,bool)), this,
        SLOT(displayError(QString,bool)));

    rulesInitialized(ruleCheckerPtr->init());
}
示例#7
0
void MainFrm::initSecondaryFrm(SecondaryFrm* frm)
{
    frm->hide();
    vSecondaryFrms.push_back(frm);

     connect(frm, SIGNAL(showStatus(QString)), this,
    SLOT(statusShow(QString)));

     connect(frm, SIGNAL(showError(QString, const bool)), this,
    SLOT(displayError(QString, const bool)));

     connect(frm, SIGNAL(hideFrm()), this,
    SLOT(closeSecondaryFrm()),Qt::UniqueConnection);
}
示例#8
0
void MainFrm::loadFile()
{
    if (pFrmReports->isVisible())
        closeSecondaryFrm(pFrmReports);

    QString fileName = QFileDialog::getOpenFileName(this,
     tr("Open Project"), tr(""), tr("Project Files (*.xml)"));

    if (!fileName.isEmpty()){
        if (!readXMLFile(fileName))
            this->displayError(tr("Could not parse XML file! Are you sure this is a valid project file?"),true);
        else
            loadTabs();
            setCurrentFile(fileName);
            statusShow(tr("File loaded"));
    }
}
示例#9
0
void MainFrm::displayError(QString strError, const bool bShowMsgBox)
{
    //! Display MsgBox with Error
    /*!
    This implementation of the msgbox functionality
    uses a container for storing the shared_pointers with msgsboxes;
    We need to have pointers, so that they live outside the scope of this function
    and eventually more than one, as multiple error boxes can popup from nested classes.
    To prevent the container from growing forever, we clean it everytime we come to this function
    (b4 adding more boxes!), so its maximum size at a certain moment won't never exceed the number simultaneously displayed msgboxes!
    */

    cleanupMsgBoxes();

    statusShow(strError);
    if (bShowMsgBox){
        m_listMsgBoxes.push_back(MsgBoxPtr(new CustomMsgBox(this)));
        m_listMsgBoxes.last().get()->lbMsg->setWordWrap(true);
        m_listMsgBoxes.last().get()->fillDialog(tr("Error"),strError);
        m_listMsgBoxes.last().get()->show();
    }
}
/**
 * 开始备份
 */
int LzBackupQueue::backup_start(QString filename, int tunnelid, bool isinterrupted, qint64 interruptedfilepos)
{
    if (!SlaveSetting::getSettingInstance()->getHasNasAccessIP())
        return -1;

    QString nasserverip = SlaveSetting::getSettingInstance()->getNASAccessIP();
    if (nasserverip.compare("") == 0)
    {
        backup_handleError(filename, tunnelid, QObject::tr("NAS设备IP地址%1未配置!").arg(nasserverip));
        return -2;
    }
    QString projectfilename = LzProjectAccess::getLzProjectAccessInstance()->getProjectFilename(LzProjectClass::Backup);
    // 任务源文件路径
    current_sourcefile_dir = SlaveSetting::getSettingInstance()->getParentPath() + "\\" + projectfilename.left(projectfilename.size() - 5) + "\\collect\\";
    QString sendfile = current_sourcefile_dir + filename;
    // 加入目标NAS的存储路径
    current_directionfile_dir = QString("\\\\%1\\LanZhou\\").arg(nasserverip) +  "\\" + projectfilename.left(projectfilename.size() - 5) + "\\collect\\";
    QString todir = current_directionfile_dir + filename;

    // 开启备份线程
    if (thread != NULL)
    {
        delete thread;
        thread = NULL;
    }
    thread = new LzSerialStorageBackupThread();
    connect(thread, SIGNAL(finish(int, QString, qint64)), this, SLOT(receiveThreadFinish(int, QString, qint64)));
    connect(thread, SIGNAL(statusShow(qint64, QString)), this, SLOT(receiveStatusShow(qint64, QString)));

    if (isinterrupted)
        thread->initCopy(sendfile, todir, false, isinterrupted, interruptedfilepos);
    else
        thread->initCopy(sendfile, todir, true, isinterrupted, interruptedfilepos);

    thread->start();
    
    return 0;
}
示例#11
0
void MainFrm::initTabs()
{
    pFrmFrame=new FrmFrame(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmFrame);

     connect(pFrmFrame, SIGNAL(disableTabs(bool)), this,
    SLOT(disableTabs(bool)));

    pFrmMinorStrata=new FrmMinorStrata(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmMinorStrata);
    pFrmCell=new FrmCell(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmCell);
    pFrmVesselType=new FrmVesselType(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmVesselType);
    pFrmVessel=new FrmVessel(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmVessel);
    pFrmTrip=new FrmTrip(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmTrip);
    pFrmOperation=new FrmOperation(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmOperation);
    pFrmCatch=new FrmCatch(m_roleDef,sSample,ruleCheckerPtr);
    initPreviewTab(pFrmCatch);

    pFrmFrameDetails=new FrmFrameDetails();
     connect(pFrmFrameDetails, SIGNAL(hideFrameDetails(bool)), this,
    SLOT(hideFrameDetails()));

     connect(pFrmFrameDetails, SIGNAL(showStatus(QString)), this,
    SLOT(statusShow(QString)));

     connect(pFrmFrameDetails, SIGNAL(showError(QString, const bool)), this,
    SLOT(displayError(QString, const bool)));

     connect(pFrmMinorStrata, SIGNAL(applyChanges2FrameDetails()), pFrmFrameDetails,
    SLOT(onApplyChanges2FrameDetails()));

     connect(pFrmFrameDetails, SIGNAL(AppliedChanges2FrameDetails()), pFrmMinorStrata,
    SLOT(editFinished()));

     connect(pFrmCell, SIGNAL(applyChanges2FrameDetails()), pFrmFrameDetails,
    SLOT(onApplyChanges2FrameDetails()));

     connect(pFrmFrameDetails, SIGNAL(AppliedChanges2FrameDetails()), pFrmCell,
    SLOT(editFinished()));

    gridLayout->addWidget(pFrmFrameDetails);
    pFrmFrameDetails->hide();

    pFrmSampling=new FrmSampling(m_roleDef,sSample,ruleCheckerPtr);
     connect(pFrmSampling, SIGNAL(hideFrmSampling(bool)), this,
    SLOT(hideFrmSampling()));

     connect(pFrmSampling, SIGNAL(showStatus(QString)), this,
    SLOT(statusShow(QString)));

     connect(pFrmSampling, SIGNAL(showError(QString, const bool)), this,
    SLOT(displayError(QString, const bool)));

     connect(pFrmFrame, SIGNAL(setFrmSamplingMode(const FrmSampling::MODE)), pFrmSampling,
    SLOT(setMode(const FrmSampling::MODE)));

     connect(pFrmFrame, SIGNAL(applyChanges2FrmSampling(const bool)), pFrmSampling,
    SLOT(onApplyChanges2FrmSampling(const bool)));

     connect(pFrmSampling, SIGNAL(AppliedChanges2SamplingFrame()), pFrmFrame,
    SLOT(editFinished()));

    gridLayout->addWidget(pFrmSampling);
    pFrmSampling->hide();

    // Connect all the signals
     for (int i = 0; i < vTabs.size(); ++i) {

         connect(vTabs.at(i), SIGNAL(currentHelpId(const QString)), this,
        SLOT(setCurHelpId(const QString)),Qt::UniqueConnection);

         connect(vTabs.at(i), SIGNAL(navigate(const bool, const int)), this,
        SLOT(navigateThroughTabs(const bool, const int)),Qt::UniqueConnection);

         connect(vTabs.at(i), SIGNAL(showFrameDetails(const FrmFrameDetails::Mode, const FrmFrameDetails::Persistence, Sample*,QList<int>, const int)), this,
        SLOT(showFrameDetails(const FrmFrameDetails::Mode, const FrmFrameDetails::Persistence, Sample*,QList<int>, const int)),Qt::UniqueConnection);

         connect(pFrmFrameDetails, SIGNAL(hideFrameDetails(bool)), vTabs.at(i),
        SIGNAL(hideFrameDetails(bool)),Qt::UniqueConnection);

         connect(vTabs.at(i), SIGNAL(showFrmSampling()), this,
        SLOT(showFrmSampling()),Qt::UniqueConnection);

         connect(pFrmSampling, SIGNAL(hideFrmSampling(bool)), vTabs.at(i),
        SIGNAL(hideFrmSampling(bool)),Qt::UniqueConnection);

         connect(vTabs.at(i), SIGNAL(showError(QString,bool)), this,
        SLOT(displayError(QString,bool)),Qt::UniqueConnection);

         connect(vTabs.at(i), SIGNAL(showStatus(QString)), this,
        SLOT(statusShow(QString)),Qt::UniqueConnection);

         //each remove on a table, triggers a preview wuery on the following tabs
         //(so that we don't have "ghost" records lying around the tables!)
         for (int j=i+1; j < vTabs.size(); ++j){
             connect(vTabs.at(i), SIGNAL(recordRemoved()), vTabs.at(j),
            SLOT(setPreviewQuery()));
         }

        this->tabWidget->insertTab(vTabs.size()
        ,vTabs.at(i), vTabs.at(i)->title());

         if (i>0)
             tabWidget->setTabEnabled(i,false);

     }
     tabWidget->setCurrentIndex(0);

}
示例#12
0
void MainFrm::loadTabs()
{
    qApp->setOverrideCursor( QCursor(Qt::BusyCursor ) );
    statusShow(tr("Wait..."));

        resetTabs();

        initTabs();

        if (pFrmFrame==0) return;
        this->tabWidget->insertTab(0,pFrmFrame, pFrmFrame->title());

        if (sSample->frameId==-1 || sSample->frameTimeId==-1) return;

        QVector<int> vSample;
        vSample << sSample->frameTimeId;
        vSample << sSample->minorStrataId;
        vSample << sSample->cellId;
        vSample << sSample->vesselTypeId;
        vSample << sSample->sampVesselId;
        vSample << sSample->tripId;
        vSample << sSample->operationId;
        vSample << sSample->catchId;

        if (vSample.size() != vTabs.size()){
            displayError(tr("Could not load project file!"),true);//TODO: improve errors!
        }else{

            bool bOk=true;
            int ct=0;
            QVector<int>::const_iterator it;
             for (it = vSample.begin(); it != vSample.end(); ++it){

                 if ( qobject_cast<PreviewTab*>(vTabs.at(ct))!=0){
                    PreviewTab* pTab=qobject_cast<PreviewTab*>(vTabs.at(ct));

                    if (*it!=-1){

                            if (!pTab->tableSelect(*it)){
                                displayError(tr("Could not find the saved record on form ") +
                                    vTabs.at(ct)->title(),true);
                                bOk=false;
                                break;
                            }

                            QVector<int>::const_iterator it2;
                            if (sSample->bLogBook && pTab->title()==tr("Stratum"))
                                it2=it+3;
                            else
                                it2=it+1;

                            //qDebug() << pTab->objectName() << endl;
                            if (*it2!=-1 && ct<vTabs.size()-1){
                                //|| (sSample->bLogBook && ( pTab->objectName()){
                             vTabs.at(ct)->setLoading(true);
                             if (!vTabs.at(ct)->next()){
                                bOk=false;
                                vTabs.at(ct)->setLoading(false);
                                break;
                             }
                             vTabs.at(ct)->setLoading(false);
                        }
                    }
                     ct++;

                 }//cast
             }//for

            if (bOk) statusShow(tr("Project successfully loaded."));
            else displayError (tr("Could not load tab ") + vTabs.at(ct)->title() + tr("!"),false);
        }

    qApp->setOverrideCursor( QCursor(Qt::ArrowCursor ) );
}