void IconsetDelegate::drawCheckButton(QPainter *APainter, const QStyleOptionViewItemV4 &AIndexOption, const QRect &ARect, Qt::CheckState AState) const
{
	if (ARect.isValid())
	{
		QStyleOptionViewItem checkOption(AIndexOption);
		checkOption.rect = ARect;
		checkOption.state = checkOption.state & ~QStyle::State_HasFocus;

		switch (AState)
		{
		case Qt::Unchecked:
			checkOption.state |= QStyle::State_Off;
			break;
		case Qt::PartiallyChecked:
			checkOption.state |= QStyle::State_NoChange;
			break;
		case Qt::Checked:
			checkOption.state |= QStyle::State_On;
			break;
		}

		const QStyle *style = AIndexOption.widget ? AIndexOption.widget->style()->proxy() : QApplication::style()->proxy();
		style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &checkOption, APainter, AIndexOption.widget);
	}
}
Exemplo n.º 2
0
/*
 * name : impport_doit
 * desc : Do import
 */
void PicIn_Core::import_doit()
{
    QFile file;
    QString tgtName;
    QString tgtPath;
    QString yearPath;
    QString monthPath;
    QString dayPath;
    QString srcPath;
    QDate date;
    QDir dir;

    offOption(optionCancel);

    //If we don't do this proccessEvents(),
    //progress dialog would no response until this function done.
    QApplication::processEvents(QEventLoop::AllEvents);
    for(int i = 0; i < m_fileInfoList_src.size(); i++){
        srcPath = m_fileInfoList_src.at(i).absoluteFilePath();

        tgtPath.clear();
        tgtPath = m_copyTgtList.at(i);

        dir = QDir(QFileInfo(tgtPath).dir());
        if(!dir.exists()){
            dir.mkpath(dir.absolutePath());
        }

        //
        // Copy file
        //

        QDateTime laDateTime;
        QDateTime lmDateTime;

        laDateTime = QFileInfo(srcPath).lastRead();
        lmDateTime = QFileInfo(srcPath).lastModified();

        file.copy(srcPath, tgtPath);
        setLastModifyDateTime(tgtPath, laDateTime ,lmDateTime);

        //
        // Update progress bar and check cancel
        //

        emit signal_update_progress(i);
        if(checkOption(optionCancel)){
            break;
        }

        QApplication::processEvents(QEventLoop::AllEvents);
    }

    offOption(optionCancel);
}
Exemplo n.º 3
0
int Menu::displayAndGetInput() {
	clrscr();
	
	int choice;
	bool ok = true;

	for (unsigned int i = 0; i < options.size(); ++i) {
		if (options[i].active == true)
			cout << options[i].id << ".\t" << options[i].text << endl;
	}
	cout << "Your input: ";
	cin >> choice;
	ok = checkOption(choice);

	while (!ok) {
		cout << "Wrong option. Try again:\n";
		cout << "Your input: ";
		cin >> choice;
		ok = checkOption(choice);
	}

	return choice;
}
Exemplo n.º 4
0
/*
 * name : get_file_list
 * desc : Scan indicated path and return file info list of images
 * in   :
 *   path, String of source path
 *   filters, String list of file extension name
 * ret  : List of QFileInfo for all files under indicated path
 */
QFileInfoList
PicIn_Core::get_file_list(QString path, QStringList filters)
{
    QDir dir(path);
    QStringList nameFilters;

    //
    // Scan files
    //

    QFileInfoList fileInfoList;

    if(filters.size() > 0){
        nameFilters.append(filters);
    }
    dir.setFilter(QDir::NoSymLinks | QDir::Files);
    dir.setNameFilters(nameFilters);
    dir.setSorting(QDir::Name);

    fileInfoList = dir.entryInfoList();

    //
    // Scan sub directory
    //

    if(checkOption(optionSubDir)){
        QFileInfoList dirInfoList;

        dir.setFilter(QDir::NoSymLinks | QDir::Dirs | QDir::NoDotAndDotDot);
        nameFilters.clear();
        dir.setNameFilters(nameFilters);
        dir.setSorting(QDir::Name);

        dirInfoList = dir.entryInfoList();

        for(int i = 0; i < dirInfoList.size(); i++){
            fileInfoList.append(
                get_file_list(dirInfoList.at(i).absoluteFilePath(),
                filters));
        }
    }

    return fileInfoList;
}
Exemplo n.º 5
0
/*
**NOTE**
For all class member functions, check their respective header files
for the DETAILED (Post/Pre condition) description of the function.
*/
int main(int argc,char* argv[])//argv[1] will be the csv inputfile name.
{
 
 //If statement to check if an inputfile command line arguement is passed.
 if(argc<2)
 {
   cout << "\nError usage, please run the program in the following manner:" << endl;
   cout << argv[0] << " CSV_INPUT_FILE_NAME\n" << endl;
   exit(1); //Display usage and exit program if no command line arguement.
 }

//////////////////////////
//TOKEN EXTRACTION BLOCK//
//////////////////////////
 AddressBook bookOne;
 //Create AddressBook object bookOne
 bookOne.pushTitle();
 //This function pushes the title line into the contact vector at position 0.(i.e "First Name", "Last Name" etc...)
 /*Could probably leave this out by reading the first line of the given input file which also contains
 the title line.*/

 vector<string> myString;
 //myString will store text lines from csv inputfile argv[1]
 string fileline, currentline, substring;
 //fileline=line of file from text to be push back into myString
 //currentline=current line that is being looked at by token extraction algorithm
 //substring=token extracted to be pushed into the actual Addressbook Contact


    	//File extration is done here
	ifstream myfile(argv[1]);
	
	//Start extraction line by line if able to open file.
	if(myfile.is_open())
	{
		while(myfile)
		{
			getline(myfile, fileline);
			if(fileline.length()!=0)
			{
				myString.push_back(fileline);
			}
		}
    		myfile.close();
	}

	//Else if the file does not exist, asks user to double check that the files is in the directory.
	else
	{
		cout << "\n*WARNING* CSV File not found in directory. Please check for file:\"" << argv[1] << "\"\n" << endl;
		exit(1);		
	}

    //Token extraction loop/algorithm starts here.
    //Took me a while but I figured it out =)!
    for(int i=1; i<myString.size(); i++) //this for loop will run for the length of myString
    {
        bookOne.iPush();
        //iPush will pushback the vector to make room for the new incomming line.

        currentline=myString.at(i);
        //currentline will get each line from myString from first to end

        //x is left "
        //y is right "
        //token will count token # 1-11 for each field.
        int x=0, y=0, token=0;
        while(token<11)//The algorithm should keep looking for tokens until counter hits 11 tokens
        {
            //x starts looking for the first " from y (0 initially at the start of the string/loop)
            x=currentline.find_first_of("\"", y);
            //y will start looking for the next " starting from x+1
            y=currentline.find_first_of("\"",x+1);

            //This if check is not really needed but to be save, x" will always be less than y"
            if(x<y)
            {
                token++;
            }
            substring=currentline.substr(x+1,(y-x)-1);
            //substring is the token which will always be found at x+1 to y-1
            //to get the length, starting from x+1, it is (y-x)-1...(there are also other ways to calculate)
            bookOne.buildData(i,substring,token);
            //After token is extracted to substring, it is pushed to the address book with it's respective
            //token index counter "token"

            //This was the tricky part...took me a while to figure it out =P
            //y needs to get +1 to prevent x from finding y's " in the next loop. DUHHH!!
            //Also this can be done with a third variable to look for commas but this is more efficient/easier.
            y++;

        }

    }//for loop ends here bringing the extraction process to an end.

    //This loop will validate the newly built vector of contacts. (Start at 1 as 0 is the title line)
    for(int i=1; i<bookOne.vectorSize()-1; i++) //vectorsize returns the size the vector Contact data.
    {
        if(bookOne.contactValidate(i)==0)//this boolean function validates and DELETES invalid contacts.
        {
            bookOne.contactValidate(i);//calling the actual function DELETES invalid contacts (more detail in header file)
            i=1; //Thus bringing i back to 1 is needed to check for all invalid contacts in the new vector size.
        }
    }



/////////////////////
//MAIN OPTION BLOCK//
/////////////////////
 string option;
 //option is the variable for the menu option input from the user
 do{ //this do loop will run wile the option is not Q or q for quit.
    do{ //this do loop will run until a valid option is received from the user.
        displayMenu();
        cout << "Select an option:";
        cin >> option;
        //if the option is longer than 1 character. (can probably leave out >1 as function checks for length also)
        if(checkOption(option)==false || option.length()>1)
        {
            cout << "Invalid choice please try again.." << endl; //output invalid choice statement.
        }
    }while(checkOption(option)==false);

    //Program will get here only if option is valid.
    //Options are listed in order shown on project 3 description

        //////////////////////////////
        //OPTION [A] - Add a contact//
        //////////////////////////////
    if(option=="A" || option=="a")
    {
        //Function A uses push_back to add the new contact
        //Check AddressBook header/source file for more detail.
        bookOne.functionA();

        //if the new added push_back vector is valid (NOTE* if valid this function will NOT delete)
        if(bookOne.contactValidate(bookOne.vectorSize()-1)==1)
        {
            //Thus print detail should print the last entry added which is vector size-1;
            bookOne.printDetail(bookOne.vectorSize()-1);
            cout << "\n**New contact added to the end of the list at position " << bookOne.vectorSize()-1 << endl;
        }

        else //no need to call function again as the first if statement already called it and will delete if it's invalid.
        {    //will enter this else if it's deleted, in that case output the error message below.
            cout <<"\nInvalid contact..."
                 <<"\nPlease input valid/non space leading values for the first four fields." << endl;
        }
    }

        //////////////////////////////////////////
        //OPTION [D] - Display by sorted contact//
        //////////////////////////////////////////
    else if(option=="D" || option=="d")
    {
        //sort is the token # which it needs to be sorted by. (1-4 only)
        int sort=0;

        //do-while loop will run until a valid token choice is given.
        do{
            cout << "\nWhich field would you like to sort by?"
                << "\n1)Last Name"
                << "\n2)First Name"
                << "\n3)Nickname"
                << "\n4)Email 1"
                << "\n--------------"
                << "\nEnter Choice:";
            cin  >> sort;

            //if statement to reprompt user for valid choice
            if(sort<=0 || sort > 4)
            {
                cout << "**Error choice input, please enter choice 1-4." << endl;
            }
        }while(sort<=0 || sort > 4);

        //functionD sorts the contacts accordint to token sort
        //I used the same sorting method as my project 2!! =)
        //More in detail in AddressBook header/source file
        bookOne.functionD(sort);

        //Print preview the newly sorted contacts
        bookOne.printPreview();
    }

        ///////////////////////////////////////////
        //OPTION [C] - Display details of contact//
        ///////////////////////////////////////////
    else if(option=="C" || option=="c")
    {
        //Simply print out the details of the desired contact entry.
        int entry=0;
        bookOne.printPreview();
        do{//do-while loop to keep the entry selection within bounds of the valid vector.
            cout << "Which entry # would you like to view in detail?:";
            cin >> entry;
            if(entry<0 || entry>bookOne.vectorSize()-1)
            {
                cout << "\n**Error entry #, please try again.." << endl;
            }
        }while(entry<0 || entry>bookOne.vectorSize()-1);
        //printDetail will print the details of the desired entry.
        bookOne.printDetail(entry);

    }
Exemplo n.º 6
0
/*
 * name : get_copyTgt_List
 * desc : Scan whole source list and target path,
 *        if path has existed and optionOverwrite is off,
 *        the source path would removed from list
 */
void PicIn_Core::get_copyTgt_List(void)
{
    QFile file;
    QString tgtName;
    QString tgtPath;
    QString yearPath;
    QString monthPath;
    QString dayPath;
    QString srcPath;
    QDate date;
    QDir dir;
    QFileInfoList tempSrcList;

    tempSrcList.clear();
    m_copyTgtList.clear();

    for(int i = 0; i < m_fileInfoList_src.size(); i++){
        srcPath = m_fileInfoList_src.at(i).absoluteFilePath();

        tgtName.clear();
        tgtName.append(m_fileInfoList_src.at(i).fileName());

        tgtPath.clear();
        tgtPath.append(m_pathList_target.at(0)); // Only support 1 target path

        //
        // Check whether need to separate pics to folders as date
        //

        if(checkOption(optionExifDate)){
            date = getExifDate(srcPath);
        }
        if(!date.isValid() || !checkOption(optionExifDate)){
            date = m_fileInfoList_src.at(i).lastModified().date();
        }

        yearPath.clear();
        monthPath.clear();
        dayPath.clear();
        if(checkOption(optionDirYear)){
            yearPath.sprintf("/%04d/", date.year());
            tgtPath.append(yearPath);
        }
        if(checkOption(optionDirMon)){
            monthPath.sprintf("/%02d/", date.month());
            tgtPath.append(monthPath);
        }
        if(checkOption(optionDirDay)){
            dayPath.sprintf("/%02d/", date.day());
            tgtPath.append(dayPath);
        }

        //
        // Check whether file need to be copied
        //

        tgtPath.append(tgtName);
        if(!file.exists(tgtPath) || checkOption(optionOverwrite)){
            m_copyTgtList.append(tgtPath);
            tempSrcList.append(m_fileInfoList_src.at(i));
        }
    }

    m_fileInfoList_src = tempSrcList;

    return;
}
void lvDCOMInterface::createViRef(BSTR vi_name, bool reentrant, LabVIEW::VirtualInstrumentPtr& vi)
{
	epicsThreadOnce(&onceId, initCOM, NULL);
	std::wstring ws(vi_name, SysStringLen(vi_name));
	HRESULT hr;
	if ( (m_lv != NULL) && (m_lv->CheckConnection() == S_OK) )
	{
		;
	}
	else if (m_host.size() > 0)
	{
		std::cerr << "(Re)Making connection to LabVIEW on " << m_host << std::endl;
		CComBSTR host(m_host.c_str());
		m_pidentity = createIdentity(m_username, m_host, m_password);
		COAUTHINFO* pauth = new COAUTHINFO;
		COSERVERINFO csi = { 0, NULL, NULL, 0 };
		pauth->dwAuthnSvc = RPC_C_AUTHN_WINNT;
		pauth->dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
		pauth->dwAuthzSvc = RPC_C_AUTHZ_NONE;
		pauth->dwCapabilities = EOAC_NONE;
		pauth->dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
		pauth->pAuthIdentityData = m_pidentity;
		pauth->pwszServerPrincName = NULL;
		csi.pwszName = host;
		csi.pAuthInfo = pauth;
		MULTI_QI mq[ 1 ] = { 0 }; 
		mq[ 0 ].pIID = &IID_IDispatch;  // &LabVIEW::DIID__Application; // &IID_IDispatch; 
		mq[ 0 ].pItf = NULL; 
		mq[ 0 ].hr   = S_OK; 
		hr = CoCreateInstanceEx( m_clsid, NULL, CLSCTX_REMOTE_SERVER | CLSCTX_LOCAL_SERVER, &csi, 1, mq ); 
		if( FAILED( hr ) ) 
		{ 
			hr = CoCreateInstanceEx( m_clsid, NULL, CLSCTX_ALL, &csi, 1, mq );
		}
		if( FAILED( hr ) ) 
		{
			throw COMexception("CoCreateInstanceEx (LabVIEW) ", hr);
		} 
		if( S_OK != mq[ 0 ].hr || NULL == mq[ 0 ].pItf ) 
		{ 
			throw COMexception("CoCreateInstanceEx (LabVIEW)(mq) ", mq[ 0 ].hr);
		} 
		setIdentity(m_pidentity, mq[ 0 ].pItf);
		m_lv.Release();
		m_lv.Attach( reinterpret_cast< LabVIEW::_Application* >( mq[ 0 ].pItf ) ); 
		std::cerr << "Successfully connected to LabVIEW on " << m_host << std::endl;
	}
	else
	{
		std::cerr << "(Re)Making local connection to LabVIEW" << std::endl;
		m_pidentity = NULL;
		m_lv.Release();
		hr = m_lv.CoCreateInstance(m_clsid, NULL, CLSCTX_LOCAL_SERVER);
		if( FAILED( hr ) ) 
		{
			throw COMexception("CoCreateInstance (LabVIEW) ", hr);
		} 
		std::cerr << "Successfully connected to local LabVIEW" << std::endl;
	}
	if (reentrant)
	{
		vi = m_lv->GetVIReference(vi_name, "", 1, 8);
		setIdentity(m_pidentity, vi);
	}
	else
	{
		//If a VI is reentrant then always get it as reentrant
		vi = m_lv->GetVIReference(vi_name, "", 0, 0);
		setIdentity(m_pidentity, vi);
		if (vi->IsReentrant)
		{
			vi = m_lv->GetVIReference(vi_name, "", 1, 8);
			setIdentity(m_pidentity, vi);
			reentrant = true;
		}
	}
	ViRef viref(vi, reentrant, false);
	// LabVIEW::ExecStateEnum::eIdle = 1
	// LabVIEW::ExecStateEnum::eRunTopLevel = 2
	if (vi->ExecState == LabVIEW::eIdle)
	{
		if ( checkOption(viStartIfIdle) ) 
		{
			std::cerr << "Starting \"" << CW2CT(vi_name) << "\" on " << (m_host.size() > 0 ? m_host : "localhost") << std::endl;
			vi->Run(true);
			viref.started = true;
		}
		else if ( checkOption(viWarnIfIdle) )
		{
			std::cerr << "\"" << CW2CT(vi_name) << "\" is not running on " << (m_host.size() > 0 ? m_host : "localhost") << " and autostart is disabled" << std::endl;
		}
	}
	m_vimap[ws] = viref;
}