Ejemplo n.º 1
0
int MimeDB::GetMimeList( const unicode_t* fileName, ccollect<int>& outList )
{
	ccollect<int> temp1;

	if ( globs.GetMimeList( fileName, temp1 ) > 0 )
	{

		std::unordered_map<int, bool> hash;
		int i;

		for ( i = 0; i < temp1.count(); i++ )
		{
			bool Exists = hash.find( temp1[i] ) != hash.end(); 

			if ( !Exists )
			{
				outList.append( temp1[i] );
				hash[ temp1[i] ] = true;

				AddParentsRecursive( temp1[i], &outList, &hash );
			}
		}
//		for (i=0; i<temp1.count(); i++)
//			AddParentsRecursive(temp1[i], &outList, &hash);
	}

	return outList.count();
}
Ejemplo n.º 2
0
int MimeGlobs::GetMimeList( const unicode_t* fileName, ccollect<int>& list )
{
	std::vector<unicode_t> ext = GetFileExtLC( fileName );

	if ( ext.data() )
	{
		auto iter = m_ExtMimeHash.find( ext.data() );

		if ( iter != m_ExtMimeHash.end() )
		{
			const std::vector<int>& p = iter->second;

			for ( size_t i = 0, cnt = p.size(); i < cnt; i++ )
			{
				list.append( p[ i ] );
			}
		}
	}

	{
		//пробег по маскам
		const unicode_t* fn = find_right_char<unicode_t>( fileName, '/' );

		if ( fn ) { fn++; }
		else { fn = fileName; }

		std::vector<unicode_t> str( unicode_strlen( fn ) + 1 );
		unicode_t* s = str.data();

		while ( *fn ) { *( s++ ) = UnicodeLC( *( fn++ ) ); }

		*s = 0;

		for ( MaskNode* p = maskList; p; p = p->next )
			if ( p->mask.data() && accmask( str.data(), p->mask.data() ) )
			{
				list.append( p->mime );
			}
	}

	return list.count();
}
Ejemplo n.º 3
0
void InitOperCharsets()
{
	csList.clear();
	charset_struct *list[128];
	int count = charset_table.GetList(list, 128);
	cstrhash<charset_struct*> hash;
	int i;
	for (i = 0; i<count; i++) hash[list[i]->name] = list[i];

	ccollect< carray<char> > stringList;
	if (LoadStringList(charsetSection, stringList))
	{
		for (i = 0; i<stringList.count(); i++) 
		{
			charset_struct ** p = hash.exist(stringList[i].ptr());
			if (p)	csList.append(*p);
		}
	}



	if (csList.count()<=0)
	{
		const char *lang = sys_locale_lang();
		if (!strcmp("ru", lang))
		{
#ifdef WIN32		
			csList.append(charset_table[CS_WIN1251]);
			csList.append(charset_table[CS_CP866]);
			csList.append(charset_table[CS_UTF8]);
#else
			csList.append(charset_table[CS_UTF8]);
			csList.append(charset_table[CS_WIN1251]);
			csList.append(charset_table[CS_KOI8R]);
			csList.append(charset_table[CS_CP866]);
#endif
		}
	}

	if (csList.count()<=0)
	{
		csList.append(charset_table[CS_UTF8]);
		csList.append(&charsetLatin1);
	}
}
Ejemplo n.º 4
0
bool LoadStringList(const char *section, ccollect< carray<char> > &list)
{
	char name[64];
	list.clear();
	for (int i=1; ; i++)
	{
		snprintf(name, sizeof(name), "v%i", i);
		carray<char> s = RegReadString(section, name, "");
		if (!s.ptr() || !s[0]) break;
		list.append(s);
	}

	return true;
}
Ejemplo n.º 5
0
int AppDefListFile::GetAppList( int mime, ccollect<int>& appList )
{
	auto i = hash.find( mime );

	ccollect<int, 1>* p = ( i == hash.end() ) ? nullptr : &(i->second);

	if ( p )
	{
		for ( int i = 0, cnt = p->count(); i < cnt; i++ )
		{
			appList.append( p->get( i ) );
		}
	}

	return appList.count();
}
Ejemplo n.º 6
0
int MimeSubclasses::GetParentList( int mime, ccollect<int>& list )
{
	auto i = hash.find( mime );

	ccollect<int>* p = ( i == hash.end() ) ? nullptr : &(i->second);

	if ( p )
	{
		for ( int i = 0, cnt = p->count(); i < cnt; i++ )
		{
			list.append( p->get( i ) );
		}
	}

	return list.count();
}
Ejemplo n.º 7
0
static bool LangListLoad(sys_char_t *fileName, ccollect<LangListNode> &list)
{
	list.clear();
	try {
		BFile f;
		f.Open(fileName);
		char buf[4096];
		
		while (f.GetStr(buf, sizeof(buf)))
		{
			char *s = buf;
			while (IsSpace(*s)) s++;
			if (*s == '#') 	continue;

			if (!*s) continue;
			
			ccollect<char,0x100> id;
			ccollect<char,0x100> name;
			
			while (*s && !IsSpace(*s)) {
				id.append(*s);
				s++;
			}
			
			while (IsSpace(*s)) s++;
			
			int lastNs = -1;
			for (int i = 0; *s; i++, s++) {
				if (*s == '#') break;
				if (!IsSpace(*s)) lastNs = i;
				name.append(*s);
			}
			if (id.count()<=0 || lastNs < 0) continue;
			id.append(0);
			name.append(0);
			name[lastNs + 1] = 0; 
			
			LangListNode(id.ptr(), name.ptr());
			list.append(LangListNode(id.ptr(), name.ptr()) );
		}
	} catch (cexception *ex) {
		ex->destroy();
		return false;
	}
	return true;
}
Ejemplo n.º 8
0
int AppDB::GetAppList( int mime, ccollect<int>& appList )
{
	defList.GetAppList( mime, appList );

	auto i = mimeMapHash.find( mime );

	ccollect<int>* p = ( i == mimeMapHash.end() ) ? nullptr : &(i->second);

	if ( p )
	{
		for ( int i = 0, cnt = p->count(); i < cnt; i++ )
		{
			appList.append( p->get( i ) );
		}
	}

	return appList.count();
}
Ejemplo n.º 9
0
void CharsetDlg1::Add()
{
	charset_struct *buf[128];
	int bufCount = GetOtherCharsetList(buf, 128);

	CharsetDialog dlg( (NCDialogParent*) Parent(), 0, _LT("Add charsets"), buf, bufCount);
	int ret = dlg.DoModal();
	if (ret == CMD_OK) 
	{
		charset_struct * p =  dlg.CurrentCharset();
		if (!p) return;
		csList.append(p);
		list.SetList(csList.ptr(), csList.count());
		list.MoveCurrent(csList.count()-1);
		SaveOperCharsets();
		return;
	}
}
Ejemplo n.º 10
0
bool LoadStringList(const char *section, ccollect< carray<char> > &list)
{
	try {
		SysTextFileIn in;
				
		FSPath path = configDirPath;
		path.Push(CS_UTF8, carray_cat<char>(section, ".cfg").ptr());
		in.Open( (sys_char_t*)path.GetString(sys_charset_id) );
		
		char buf[4096];
		while (in.GetLine(buf, sizeof(buf))) 
		{
			char *s = buf;
			while (*s>0 && *s<=' ') s++;
			if (*s) list.append(new_char_str(s));
		}
	} catch (cexception *ex) {
		ex->destroy();
		return false;
	}
	return true;
}
Ejemplo n.º 11
0
static int _GetAppList( const unicode_t* fileName, ccollect<AppNode*>& list )
{
	if ( !mimeDb.ptr() )
	{
		if ( FileIsExist( "/usr/share/mime/globs" ) )
		{
			mimeDb = new MimeDB( "/usr/share/mime/" );
		}
		else
		{
			mimeDb = new MimeDB( "/usr/local/share/mime/" );
		}
	}

	if ( !appDb.ptr() )
	{
		if ( DirIsExist( "/usr/share/applications" ) )
		{
			appDb = new AppDB( "/usr/share/applications/" );
		}
		else
		{
			appDb = new AppDB( "/usr/local/share/applications/" );
		}
	}

	if ( !userDefApp.ptr() )
	{
		const char* home = getenv( "HOME" );

		if ( home )
		{
			userDefApp = new AppDefListFile( carray_cat<char>( home, "/.local/share/applications/mimeapps.list" ).data() );
		}
	}

	mimeDb->Refresh();
	appDb->Refresh();

	if ( userDefApp.ptr() )
	{
		userDefApp->Refresh();
	}

	ccollect<int> mimeList;

	if ( mimeDb->GetMimeList( fileName, mimeList ) )
	{
		int i;
		std::unordered_map<int, bool> hash;

		for ( i = 0; i < mimeList.count(); i++ )
		{
			ccollect<int> appList;

			if ( userDefApp.ptr() )
			{
				userDefApp->GetAppList( mimeList[i], appList );
			}

			appDb->GetAppList( mimeList[i], appList );

			for ( int j = 0; j < appList.count(); j++ )
			{
				bool Exists = hash.find( appList[j] ) != hash.end();
				if ( !Exists )
				{
					hash[appList[j]] = true;

					AppNode* p = appDb->GetApp( appList[j] );

					if ( p && p->exec.data() )
					{
						list.append( p );
					}
				}
			}
		}
	}

	return list.count();
}