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 GetNextOperCharsetId(int id)
{
	if (csList.count()<=0) return CS_UTF8;
	int i;
	for (i = 0; i<csList.count(); i++)
		if (csList[i]->id == id) break;

	return (i+1 < csList.count()) ? csList[i+1]->id : csList[0]->id;
}
Ejemplo n.º 3
0
const char *CfgLangDialog::GetId()
{ 
	int n = _list.GetCurrent();
	if (n <= 0 ) return "+";
	if (n == 1) return "-";
	n-=2;
	if (n >= nodeList->count()) return "+";
	return nodeList->get(n).id.ptr();
}
Ejemplo n.º 4
0
void CharsetDlg1::Del()
{
	int n = list.GetCurrent();
	if (n >=0 && n<csList.count() && csList.count() > 1 &&
			NCMessageBox((NCDialogParent*)Parent(), _LT("Del"), 
				carray_cat<char>(_LT("Delete element")," '", csList[n]->name ,"' ?").ptr(), false, bListOkCancel) == CMD_OK)
	{
		csList.del(n);
		list.SetList(csList.ptr(), csList.count());
		SaveOperCharsets();
		list.Invalidate();
	}
}
Ejemplo n.º 5
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.º 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
void SaveStringList(const char *section, ccollect< carray<char> > &list)
{
	try {
		SysTextFileOut out;
				
		FSPath path = configDirPath;
		path.Push(CS_UTF8, carray_cat<char>(section, ".cfg").ptr());
		out.Open( (sys_char_t*)path.GetString(sys_charset_id) );
		
		for (int i = 0; i<list.count(); i++)
		{
			if (list[i].ptr() && list[i][0])
			{
				out.Put(list[i].ptr());
				out.PutC('\n');
			}
		}
		
		out.Flush();
		out.Close();
		
	} catch (cexception *ex) {
		ex->destroy();
		return ;
	}
}
Ejemplo n.º 8
0
void SaveOperCharsets()
{
	ccollect< carray<char> > stringList;
	for (int i = 0; i<csList.count(); i++)
		stringList.append(new_char_str(csList[i]->name));
	SaveStringList(charsetSection, stringList);
}
Ejemplo n.º 9
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.º 10
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.º 11
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.º 12
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.º 13
0
void StyleOptDialog::RefreshFontInfo()
{
	int count = pList->count();
	int cur = fontList.GetCurrent();
	
	const char *s = "";
	if (count>=0 && cur>=0 && cur<count)
	{
		int n = fontList.GetCurrentInt();
		if (pList->get(n).newFont.ptr())
			s = pList->get(n).newFont->printable_name();
		else
		if (pList->get(n).oldFont)
			s = pList->get(n).oldFont->printable_name();
	}
		
	fontNameStatic.SetText(utf8_to_unicode(s).ptr());
}
Ejemplo n.º 14
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.º 15
0
static int 	GetOtherCharsetList(charset_struct **list, int size)
{
		charset_struct *tempList[128];
		int retCount = charset_table.GetList(tempList, 128);
		int i;
		cinthash<int, bool> hash;
		for (i = 0; i<csList.count(); i++) hash[csList[i]->id] = true;
		int n = 0;
		for (i = 0; i<retCount; i++)
			if (!hash.exist(tempList[i]->id) && n<size)
				list[n++] = tempList[i];
		return n;
}
Ejemplo n.º 16
0
void SysOptDialog::SetCurLang(const char *id)
{
	curLangId = new_char_str(id);
	if (id[0] == '-')
		langVal.SetText( utf8_to_unicode( _LT("English") ).ptr() );
	else if (id[0]=='+') 
		langVal.SetText( utf8_to_unicode( _LT("Autodetect") ).ptr() );
	else {
		for (int i = 0; i<list.count(); i++)
		{
			if (!strcmp(list[i].id.ptr(), id)) {
				langVal.SetText( utf8_to_unicode( list[i].name.ptr() ).ptr() );
				return;
			}
		}
		langVal.SetText( utf8_to_unicode( id ).ptr() );
	}
}
Ejemplo n.º 17
0
void SaveStringList(const char *section, ccollect< carray<char> > &list)
{
	int n = 1;
	char name[64];

	for (int i = 0; i<list.count(); i++)
	{
		if (list[i].ptr() && list[i][0])
		{
			snprintf(name, sizeof(name), "v%i", n);
			if (!RegWriteString(section, name, list[i].ptr()))
				break;
			n++;
		}
	}

	snprintf(name, sizeof(name), "v%i", n);
	RegWriteString(section, name, "");
}
Ejemplo n.º 18
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.º 19
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.º 20
0
int GetFirstOperCharsetId()
{
	return csList.count()>0 ? csList[0]->id : CS_UTF8;
}
Ejemplo n.º 21
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();
}
Ejemplo n.º 22
0
bool StyleOptDialog::Command(int id, int subId, Win *win, void *data)
{
	
	if (win == &fontList)
	{
		RefreshFontInfo();
		return true;
	}
#ifdef _WIN32
	if (id == CMD_CHFONT)
	{
		int count = pList->count();
		int cur = fontList.GetCurrent();
	
		if (count<=0 || cur<0 || cur>=count) return true;

		LOGFONT lf;
		carray<char> *pUri = pList->get(fontList.GetCurrentInt()).pUri;
		cfont::UriToLogFont(&lf, pUri && pUri->ptr() ?  pUri->ptr() : 0);

		CHOOSEFONT cf;
		memset(&cf,0,sizeof(cf));
		cf.lStructSize = sizeof(cf);
		cf.hwndOwner = GetID();
		cf.lpLogFont = &lf;
		cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT ;

		if (pList->get(fontList.GetCurrentInt()).fixed)
			cf.Flags |= CF_FIXEDPITCHONLY;


		if (ChooseFont(&cf))
		{
			cptr<cfont> p = new cfont(cfont::LogFontToUru(lf).ptr());
			if (p.ptr()) {
				pList->get(fontList.GetCurrentInt()).newFont = p;
				RefreshFontInfo();
			}
		}

		return true;
	}

#else
	if (id == CMD_CHFONT)
	{
		int count = pList->count();
		int cur = fontList.GetCurrent();
	
		if (count<=0 || cur<0 || cur>=count) return true;
		
		carray<char> *pUri = pList->get(fontList.GetCurrentInt()).pUri;
		
		cptr<cfont> p = SelectFTFont((NCDialogParent*)Parent(), pList->get(fontList.GetCurrentInt()).fixed, (pUri && pUri->ptr()) ? pUri->ptr() : 0 );
		if (p.ptr()) {
			pList->get(fontList.GetCurrentInt()).newFont = p;
			RefreshFontInfo();
		}
		
		return true;
	}
	
	if (id == CMD_CHFONTX11)
	{
		int count = pList->count();
		int cur = fontList.GetCurrent();
	
		if (count<=0 || cur<0 || cur>=count) return true;

		cptr<cfont> p = SelectX11Font((NCDialogParent*)Parent(), pList->get(fontList.GetCurrentInt()).fixed);
		if (p.ptr()) {
			pList->get(fontList.GetCurrentInt()).newFont = p;
			RefreshFontInfo();
		}
		
		return true;
	}
#endif
	
	return NCVertDialog::Command(id, subId, win, data);
}