Exemple #1
0
// XML backend helper: Split the path into a node key and an attribute key.
void Preferences::_keySplit(Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key)
{
    // everything after the last slash
    attr_key = pref_path.substr(pref_path.rfind('/') + 1, Glib::ustring::npos);
    // everything before the last slash
    node_key = pref_path.substr(0, pref_path.rfind('/'));
}
int File_inport::inport(Glib::ustring file) {
	//convert adress to file name
	int poz = file.rfind("/");
	Glib::ustring subor = Glib::ustring(file.c_str()+poz);
	File_load fil(file);
	if(fil.getType().compare(CUSTOMVIDEO)==0){
		return 1;
	}

	std::fstream vys;
	vys.open((confDir+subor).c_str(), std::fstream::in);
	if(vys.good()){
//		std::cout<<"exist"<<std::endl;
		return -1;
	}
	Glib::ustring command = "cp -n \"" + file + "\" " + confDir;
	if(system(command.c_str())!=0){
		return -2;
	}
	vys.close();
	vys.open(confFile.c_str(), std::fstream::out | std::fstream::app);
	vys<<confDir+subor<<std::endl;
	vys.close();
	return 0;
}
Exemple #3
0
/**
 * Get the full path, directory, and base file name of this running executable
 */ 
bool RegistryTool::getExeInfo(Glib::ustring &fullPath,
                              Glib::ustring &path,
                              Glib::ustring &exeName)
{

    char buf[MAX_PATH+1];
    if (!GetModuleFileName(NULL, buf, MAX_PATH))
        {
        fprintf(stderr, "Could not fetch executable file name\n");
        return false;
        }
    else
        {
        //printf("Executable file name: '%s'\n", buf);
        }

    fullPath = buf;
    path     = "";
    exeName  = "";
    Glib::ustring::size_type pos = fullPath.rfind('\\');
    if (pos != fullPath.npos)
        {
        path = fullPath.substr(0, pos);
        exeName = fullPath.substr(pos+1);
        }

    return true;
}
Exemple #4
0
void Document::renameFromKey ()
{
	if (getFileName().empty () || getKey().empty ())
		return;

	Glib::RefPtr<Gio::File> oldfile = Gio::File::create_for_uri(getFileName());

	Glib::ustring shortname = oldfile->query_info()->get_display_name();
	DEBUG ("Shortname = %1", shortname);
	Glib::RefPtr<Gio::File> parentdir = oldfile->get_parent();

	Glib::ustring::size_type pos = shortname.rfind (".");
	Glib::ustring extension = "";
	if (pos != Glib::ustring::npos)
		extension = shortname.substr (pos, shortname.length() - 1);

	Glib::ustring newfilename = getKey() + extension;
	DEBUG ("Newfilename = %1", newfilename);

	Glib::RefPtr<Gio::File> newfile = parentdir->get_child(newfilename);

	try {
		oldfile->move(newfile);
		setFileName (newfile->get_uri ());
	} catch (Gio::Error &ex) {
		Utility::exceptionDialog (&ex,
			String::ucompose (_("Moving '%1' to '%2'"),
				oldfile->get_uri (),
				newfile->get_uri ())
			);
	}
}
Exemple #5
0
void UIManager::addLocalBitmapsAsIconFactory()
{
    // Destination Gtk::IconFactory
    _iconFactory = Gtk::IconFactory::create();

    // Iterate over each file in the bitmaps dir
    std::string bitmapsPath = GlobalRegistry().get(RKEY_BITMAPS_PATH) + "/";

    Glib::Dir bitmapsDir(bitmapsPath);
    for (Glib::DirIterator i = bitmapsDir.begin();
         i != bitmapsDir.end();
         ++i)
    {
        Glib::ustring filename = *i;

		// Skip directories
		if (Glib::file_test(bitmapsPath + filename, Glib::FILE_TEST_IS_DIR))
		{
			continue;
		}

        // Load the pixbuf into an IconSet
		try
		{
			Gtk::IconSet is(
				Gdk::Pixbuf::create_from_file(bitmapsPath + filename)
			);

			// Add IconSet to Factory with "darkradiant:" stock prefix
			Glib::ustring filenameWithoutExtension = filename.substr(
				0, filename.rfind(".")
			);

			Gtk::StockID stockID(
				Glib::ustring::compose(
					"darkradiant:%1", filenameWithoutExtension
				)
			);

			_iconFactory->add(stockID, is);
		}
		catch (Gdk::PixbufError& ex)
		{
			rWarning() << "Could not load pixbuf from file: " <<
				filename << ": " << ex.what() << std::endl;
		}
		catch (Glib::FileError& ex)
		{
			rWarning() << "Could not load pixbuf from file: " <<
				filename << ": " << ex.what() << std::endl;
		}
    }

    // Add the IconFactory to the default factory list
    _iconFactory->add_default();
}
Exemple #6
0
Glib::ustring Configuration::get_name_from_path(const Glib::ustring& path) {
	Glib::ustring name;

	Glib::ustring::size_type p = path.rfind("/");
	if(p == Glib::ustring::npos) {
		name = path;
	}
	else {
		name = path.substr(p+1);
	}
	
	return name;
}
Exemple #7
0
int main (int argc, char **argv)
{
	Glib::thread_init();
	Gtk::Main kit(argc, argv);

	Glib::ustring ces = argv[0];
	Glib::ustring::size_type vzd = ces.rfind("/");
	ces = Glib::ustring(ces.c_str(), ces.c_str()+vzd);
	int a = chdir(ces.c_str());
	if(a != 0){
		std::cerr<<"ERROR chdir: "<<a<<std::endl;
	}
	Okno *Hl = new Okno();
	delete Hl;
  	return 0;
}
Exemple #8
0
bool mainwnd::open_file(const Glib::ustring& fn, bool setlist_mode)
{
    bool result;

    stop_playing();

    /*We aren't using a playlist if we've opened a file*/
    set_wsetlist_mode(setlist_mode);

    m_mainperf->clear_all();

    midifile f(fn);
    result = f.parse(m_mainperf, 0);
    m_modified = !result;

    if (!result) {
    	if(setlist_mode){
    		//We don't want dialog boxes in setlist mode!
    		printf("Error reading file: %s\n",fn.data());
    	}
    	else{
		    Gtk::MessageDialog errdialog(*this,
		            "Error reading file: " + fn, false,
		            Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
		    errdialog.run();
        }
        return false;
    }

    last_used_dir = fn.substr(0, fn.rfind("/") + 1);
    global_filename = fn;
    update_window_title();

    m_main_wid->reset();
    m_entry_notes->set_text(*m_mainperf->get_screen_set_notepad(
                m_mainperf->get_screenset()));
    m_adjust_bpm->set_value( m_mainperf->get_bpm());

    //Check what the max tick is
    m_mainperf->update_max_tick();

    return true;
}
Exemple #9
0
/**
 * Get the full path, directory, and base file name of this running executable
 */ 
bool RegistryTool::getExeInfo(Glib::ustring &fullPath,
                              Glib::ustring &path,
                              Glib::ustring &exeName)
{
    const int pathbuf = 2048;
    gunichar2 pathw[pathbuf];
    GetModuleFileNameW(NULL, (WCHAR*) pathw, pathbuf);

    gchar *utf8path = g_utf16_to_utf8(pathw, -1, 0,0,0);
    fullPath = utf8path;
    g_free(utf8path);

    path     = "";
    exeName  = "";
    Glib::ustring::size_type pos = fullPath.rfind('\\');
    if (pos != fullPath.npos)
        {
        path = fullPath.substr(0, pos);
        exeName = fullPath.substr(pos+1);
        }

    return true;
}
bool FileManager::OpenFiles(int argc, char **argv)
	{
#ifdef DEBUG
std::cout << "OPENFILES: OpenFiles called \n";
#endif // DEBUG

	// makes sure we're dealing with a clean slate
	filenames.clear();
	numfiles = 0;
	cwd_checked = false;
	initialised = false;
	
	/* //	if we have initialised already we're being called from the file selector and will
	//	accept new files now, let's set initialised and cwd_checked to 'false' and clear our file list
	if( initialised == true )
		{
		numfiles = 0;
		cwd_checked = false;
		initialised = false;
		} // */
		
#ifdef DEBUG
std::cout << "OPENFILES: get_current_dir_name(): " << get_current_dir_name() << std::endl;
#endif // DEBUG
		
	if( argc > 1 )
		{
		for(int i = 1; i < argc; i++)
			{
			if( stat(argv[i], &filemode) != 0 )
				{
				std::cout << GT( "OPENFILES: Stat Error! Level 1 " ) << argv[i] << std::endl;
				}
			else
				{
				Glib::ustring filename;
				
				// Resolve any ".." and double / in the filename and make the filename absolute
				if( Glib::path_is_absolute( argv[i] ) )
					filename = argv[i] ;
				else
					filename = (Glib::ustring)get_current_dir_name() + "/" + (Glib::ustring)argv[i];
				
				while( filename.find("..") != Glib::ustring::npos )
					{
					filename.erase( 
						filename.rfind( '/', filename.find("..")-2), 
						filename.find("..")+2 - filename.rfind( '/', filename.find("..")-2) );
					}
				while( filename.find("//") != Glib::ustring::npos )
					filename.erase(
						filename.find("//"), filename.find("//")+1 );
				if( filename[ filename.length()-1 ] == '/' )
					filename.erase( filename.length()-1, filename.length() );
					
					
				if(filemode.st_mode & S_IFREG )  // if the file is a regular file
					{
					if( filter_filename(filename) ) // and seems to be a supported format
						{
						#ifdef DEBUG
						std::cout << "FILEMANAGER: curent argv: " << filename << std::endl;
						std::cout << "FILEMANAGER: dirname from argv: " << Glib::path_get_dirname( filename ) << std::endl;
						std::cout << "FILEMANAGER: curent dir: " << get_current_dir_name() << std::endl;
						#endif
						  
						filenames.insert( filenames.end(), filename ); // insert into list
						numfiles++;
						}
					}
				else if(filemode.st_mode & S_IFDIR) 			// if the file is a directory
					{
					cwd_checked = true;
					if((currdir = opendir(filename.c_str())) != NULL) 	// open it
						{
						while( (dirinfo = readdir(currdir)) != NULL ) // run through it
							{
							// don't forget, we're doing some string to char* conversions here 
							// here to avoid memory errors.. Glib::ustring is nice!
							Glib::ustring currfile(filename); 				// store the directory name
							currfile += '/'; 							// add a directory dash
							currfile += dirinfo->d_name; 				// add the filename
							if(stat(currfile.c_str(), &filemode) != 0)  // check for filetype
								{
								std::cout << GT( "OPENFILES: Stat Error! Level 2 " ) << currfile << std::endl;
								}
							else
								{
								if( filemode.st_mode & S_IFREG && filter_filename(currfile) ) // as above
									{
					                filenames.insert( filenames.end(), currfile ); // insert into list
									numfiles++;
									}
								}
							}
						closedir(currdir);
						}
					}
				}
			}
		filenames.sort();
		file_iterator = filenames.begin();
		}

	// when only one file was openened, we'll scan through its directory
	// and give the user control over the files
	if ( numfiles == 1 && cwd_checked == false )
		{
			cwd_checked = true;

			Glib::ustring tempfilename = *file_iterator;
			
			// prepare the file's directory name in such a way that we can pass
			// it to OpenFiles() which operates on argc/argv	
			char *dirname = new char[ (Glib::path_get_dirname( *file_iterator )).length() + 1  ];
			strcpy( dirname, (Glib::path_get_dirname( *file_iterator )).c_str() );

			char *arguments[] = { "empty" , dirname };

			// we erase the list of filenames as otherwise we would have one file twice
			filenames.clear();
			numfiles = 0;

			// now let's open the file's directory and check its contents
			OpenFiles( 2, arguments );

			// now we have a new set of files in the list, we have to find the file that
			// the user actually wanted to open!

			std::list<Glib::ustring>::iterator end = filenames.end();
			while( file_iterator != end )
				{
				#ifdef DEBUG
				std::cout << "OPENFILES: Looking for " << tempfilename << " in " << (*file_iterator) << std::endl;
				#endif
				if( (*file_iterator).find( tempfilename ) != Glib::ustring::npos )
					{
					break; // break out of the while loop if we find the filename
					}
				file_iterator++;
				}
			// when we have reached the end while looking, let's just load the first image!
			// as that means that either we didn't recognize the filename in our search above
			// or there was only one file in the directory after all!
			if( file_iterator == end )
				file_iterator = filenames.begin();

			#ifdef DEBUG
			std::cout << "OPENFILES: Deleting temporary dirname. \n";
			#endif
			
			delete[] dirname;
		}	
		
	// everything seems to have worked out alright, let's return true
	if ( numfiles > 0 )
		{
		#ifdef DEBUG
		std::cout << "OPENFILES: We're all set to go and we have " << numfiles << " files." << std::endl; 
		#endif // DEBUG
		return true;
		}
		// we did not have sufficient arguments or we have made some mistake, return false
	else
		{
		#ifdef DEBUG
		std::cout << "OPENFILES: We have " << numfiles << " files." << std::endl;
		#endif
		return false;
		}	

	}