/****************************************************************************
 * MetaEdit
 *
 * meta bearbeiten
 ***************************************************************************/
bool
MetaEdit(string dir)
{
	int choice = -1;
	bool changed = false;

	dir += "meta.xml";
	string line, quelltext;

	ifstream in(dir.c_str());
	while(getline(in, line))
		quelltext += line + "\n";

	GuiWindow promptWindow(520,360);
	promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
	promptWindow.SetPosition(0, -10);
	GuiImageData btnOutline(Theme.button_small);
	GuiImageData btnOutlineOver(Theme.button_small_focus);
	GuiTrigger trigA;
	trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);

	GuiImageData dialogBox(Theme.dialog_background);
	GuiImage dialogBoxImg(&dialogBox);

	TextLine meta;
	meta.text(quelltext, 18, 440);

    int i = 0;
    int y = 90;
	int place = 25;

	int number = 7;
	int startline = 0;

	GuiText upTxt("c", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	upTxt.SetFont(symbol_ttf, symbol_ttf_size);
	upTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	upTxt.SetPosition(0, y -20);

	GuiText downTxt("d", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	downTxt.SetFont(symbol_ttf, symbol_ttf_size);
	downTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	downTxt.SetPosition(0, y + (place * (number-1)) + 15);

	GuiButton * Entrie[number];
	GuiText * EntrieTxt[number];

	for(i=0; i < number && i < (signed)meta.line.size(); i++)
	{
		EntrieTxt[i] = new GuiText(meta.line[i].c_str(), 18, (GXColor) {Theme.text_1, Theme.text_2, Theme.text_3, 255});
		EntrieTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
		Entrie[i] = new GuiButton(440, 18);
		Entrie[i]->SetLabel(EntrieTxt[i]);
		Entrie[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
		Entrie[i]->SetPosition(40, y);
		Entrie[i]->SetTrigger(&trigA);
		y += place;
	}

	GuiText titleTxt("meta.xml", 22, (GXColor){Theme.text_1, Theme.text_2, Theme.text_3, 255});
	titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	titleTxt.SetPosition(0,40);

	GuiText backTxt(tr("OK"), 22, (GXColor){Theme.button_small_text_1, Theme.button_small_text_2, Theme.button_small_text_3, 255});
	GuiImage backImg(&btnOutline);
	GuiImage backImgOver(&btnOutlineOver);
	GuiButton back(btnOutline.GetWidth(), btnOutline.GetHeight());

	back.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
	back.SetPosition(0, -25);

	back.SetLabel(&backTxt);
	back.SetImage(&backImg);
	back.SetImageOver(&backImgOver);
	back.SetTrigger(&trigA);
	back.SetState(STATE_SELECTED);

	promptWindow.Append(&dialogBoxImg);
	promptWindow.Append(&titleTxt);

	for(int x=0; x < i; x++)
		promptWindow.Append(Entrie[x]);

	if((signed)meta.line.size() >= number)
	{
		promptWindow.Append(&upTxt);
		promptWindow.Append(&downTxt);
	}

	promptWindow.Append(&back);

	HaltGui();
	mainWindow->SetState(STATE_DISABLED);
	mainWindow->Append(&promptWindow);
	mainWindow->ChangeFocus(&promptWindow);
	ResumeGui();

	while(choice == -1)
	{
		usleep(100);

		if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP) || PAD_ButtonsDown(0) & PAD_BUTTON_UP
		   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_UP)
		{
			startline = meta.text_up();

			for(int x=0; x < i; x++)
				EntrieTxt[x]->SetText(meta.line[x + startline].c_str());

			HaltResumeGui();
		}

		if(WPAD_ButtonsDown(0) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN) || PAD_ButtonsDown(0) & PAD_BUTTON_DOWN
		   || WUPC_ButtonsDown(0) & WPAD_CLASSIC_BUTTON_DOWN)
		{
			startline = meta.text_down(number);

			for(int x=0; x < i; x++)
				EntrieTxt[x]->SetText(meta.line[x + startline].c_str());

			HaltResumeGui();
		}

		if(back.GetState() == STATE_CLICKED)
			choice = 0;

		for(int x=0; x < i; x++)
		{
			if(Entrie[x]->GetState() == STATE_CLICKED)
			{
				Entrie[x]->ResetState();

				string temp = meta.line[x + startline];
				while((signed)temp.find("\n") != -1)
					temp.replace(temp.find("\n"), 1, "¶");

				char new_text[256];
				sprintf (new_text, "%s", temp.c_str());
				OnScreenKeyboard(new_text, 256, true);

				mainWindow->SetState(STATE_DISABLED);
				promptWindow.SetState(STATE_DEFAULT);

				if(strcasecmp(new_text,"NULL") != 0 )
				{
					changed = true;
					meta.line[x + startline] = new_text;
					while((signed)meta.line[x + startline].find("¶") != -1)
						meta.line[x + startline].replace(meta.line[x + startline].find("¶"), 1, "\n");

					EntrieTxt[x]->SetText(meta.line[x + startline].c_str());

					quelltext.clear();
					for(int a = 0; a < (signed)meta.line.size(); a++)
						quelltext += meta.line[a];

					meta.text(quelltext, 18, 440);
					for(int x=0; x < i; x++)
						EntrieTxt[x]->SetText(meta.line[x + startline].c_str());
				}

				break;
			}
		}
	}

	if(changed)
	{
		ofstream datei(dir.c_str());
		datei << quelltext;
	//	for(int i = 0; i < (signed)meta.line.size(); i++)
	//		datei << meta.line[i];
	}

	HaltGui();
	mainWindow->Remove(&promptWindow);
	mainWindow->SetState(STATE_DEFAULT);
	ResumeGui();
	return choice;
}
Example #2
0
/****************************************************************************
 * MenuLanguageSelect
 ***************************************************************************/
int MenuLanguageSelect() {
    int cnt = 0;
    int ret = 0, choice = 0;
    int scrollon;
    int returnhere = 0;

    GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume);
	// because destroy GuiSound must wait while sound playing is finished, we use a global sound
	if(!btnClick2) btnClick2=new GuiSound(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume);
	//	GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, Settings.sfxvolume);

    char imgPath[100];

    snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path);
    GuiImageData btnOutline(imgPath, button_dialogue_box_png);
    snprintf(imgPath, sizeof(imgPath), "%ssettings_background.png", CFG.theme_path);
    GuiImageData settingsbg(imgPath, settings_background_png);

    GuiTrigger trigA;
    trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
    GuiTrigger trigB;
    trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);

    char fullpath[100];
    int countfiles = GetAllDirFiles(Settings.languagefiles_path);

    if (!strcmp("", Settings.languagefiles_path)) {
        sprintf(fullpath, "%s", tr("Standard"));
    } else {
        sprintf(fullpath, "%s", Settings.languagefiles_path);
    }

    GuiText titleTxt(fullpath, 24, (GXColor) {0, 0, 0, 255});
    titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
    titleTxt.SetPosition(0,0);
    GuiButton pathBtn(300, 50);
    pathBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    pathBtn.SetPosition(0,28);
    pathBtn.SetLabel(&titleTxt);
    pathBtn.SetSoundOver(&btnSoundOver);
    pathBtn.SetSoundClick(btnClick2);
    pathBtn.SetTrigger(&trigA);
    pathBtn.SetEffectGrow();

    GuiImage oggmenubackground(&settingsbg);
    oggmenubackground.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
    oggmenubackground.SetPosition(0, 0);

    GuiText backBtnTxt(tr("Back") , 22, THEME.prompttext);
    backBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
    GuiImage backBtnImg(&btnOutline);
    if (Settings.wsprompt == yes) {
        backBtnTxt.SetWidescreen(CFG.widescreen);
        backBtnImg.SetWidescreen(CFG.widescreen);
    }
    GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
    backBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    backBtn.SetPosition(-190, 400);
    backBtn.SetLabel(&backBtnTxt);
    backBtn.SetImage(&backBtnImg);
    backBtn.SetSoundOver(&btnSoundOver);
    backBtn.SetSoundClick(btnClick2);
    backBtn.SetTrigger(&trigA);
    backBtn.SetTrigger(&trigB);
    backBtn.SetEffectGrow();

    GuiText defaultBtnTxt(tr("Default") , 22, THEME.prompttext);
    defaultBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
    GuiImage defaultBtnImg(&btnOutline);
    if (Settings.wsprompt == yes) {
        defaultBtnTxt.SetWidescreen(CFG.widescreen);
        defaultBtnImg.SetWidescreen(CFG.widescreen);
    }
    GuiButton defaultBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
    defaultBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    defaultBtn.SetPosition(190, 400);
    defaultBtn.SetLabel(&defaultBtnTxt);
    defaultBtn.SetImage(&defaultBtnImg);
    defaultBtn.SetSoundOver(&btnSoundOver);
    defaultBtn.SetSoundClick(btnClick2);
    defaultBtn.SetTrigger(&trigA);
    defaultBtn.SetEffectGrow();

    GuiText updateBtnTxt(tr("Update Files") , 22, THEME.prompttext);
    updateBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
    GuiImage updateBtnImg(&btnOutline);
    if (Settings.wsprompt == yes) {
        updateBtnTxt.SetWidescreen(CFG.widescreen);
        updateBtnImg.SetWidescreen(CFG.widescreen);
    }
    GuiButton updateBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
    updateBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    updateBtn.SetPosition(0, 400);
    updateBtn.SetLabel(&updateBtnTxt);
    updateBtn.SetImage(&updateBtnImg);
    updateBtn.SetSoundOver(&btnSoundOver);
    updateBtn.SetSoundClick(btnClick2);
    updateBtn.SetTrigger(&trigA);
    updateBtn.SetEffectGrow();

    customOptionList options2(countfiles);

    for (cnt = 0; cnt < countfiles; cnt++) {
        char filename[64];
        strlcpy(filename, GetFileName(cnt), sizeof(filename));
        char *dot = strchr(filename, '.');
        if (dot) *dot='\0';
        options2.SetName(cnt, "%s", filename);
        options2.SetValue(cnt, NULL);

    }

    if (cnt < 9) {
        scrollon = 0;
    } else {
        scrollon = 1;
    }

    GuiCustomOptionBrowser optionBrowser4(396, 280, &options2, CFG.theme_path, "bg_options_settings.png", bg_options_settings_png, scrollon, 10);
    optionBrowser4.SetPosition(0, 90);
    optionBrowser4.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);

    HaltGui();
    GuiWindow w(screenwidth, screenheight);
    w.Append(&oggmenubackground);
    w.Append(&pathBtn);
    w.Append(&backBtn);
    w.Append(&defaultBtn);
    w.Append(&updateBtn);
    w.Append(&optionBrowser4);
    mainWindow->Append(&w);

    w.SetEffect(EFFECT_FADE, 20);
    ResumeGui();

    while (w.GetEffect()>0) usleep(50);

    while (!returnhere) {

        if (shutdown == 1)
            Sys_Shutdown();
        else if (reset == 1)
            Sys_Reboot();

        else if (backBtn.GetState() == STATE_CLICKED) {

            backBtn.ResetState();
            break;
        }

        else if (defaultBtn.GetState() == STATE_CLICKED) {
            choice = WindowPrompt(tr("Loading standard language."),0,tr("OK"), tr("Cancel"));
            if (choice == 1) {
                sprintf(Settings.language_path, "notset");
                cfg_save_global();
                gettextCleanUp();
				HaltGui();
                CFG_Load();
				ResumeGui();
                returnhere = 2;
            }
            defaultBtn.ResetState();
			//optionBrowser4.SetFocus(1); // commented out to prevent crash
        }

        else if (updateBtn.GetState() == STATE_CLICKED) {
            choice = WindowPrompt(tr("Update all Language Files"),tr("Do you wish to update/download all language files?"),tr("OK"), tr("Cancel"));
            if (choice == 1) {

                bool network = true;
                if (!IsNetworkInit()) {
                    network = NetworkInitPrompt();
                }

                if (network) {
                    const char URL[60] = "http://usbloader-gui.googlecode.com/svn/trunk/Languages/";
                    char fullURL[300];
                    FILE *pfile;

                    URL_List LinkList(URL);
                    int listsize = LinkList.GetURLCount();

                    subfoldercreate(Settings.languagefiles_path);

                    for (int i = 0; i < listsize; i++) {

                        ShowProgress(tr("Updating Language Files:"), 0, LinkList.GetURL(i), i, listsize-1);

                        if (strcasecmp(".lang", strrchr(LinkList.GetURL(i), '.')) == 0) {

                            snprintf(fullURL, sizeof(fullURL), "%s%s", URL, LinkList.GetURL(i));

                            struct block file = downloadfile(fullURL);

                            if (file.data && file.size) {
                                char filepath[300];

                                snprintf(filepath, sizeof(filepath), "%s%s", Settings.languagefiles_path, LinkList.GetURL(i));
                                pfile = fopen(filepath, "wb");
                                fwrite(file.data, 1, file.size, pfile);
                                fclose(pfile);

                            }

                            free(file.data);
                        }
                    }
                    ProgressStop();
                    returnhere = 1;
                    break;
                }
            }
			updateBtn.ResetState();
			//optionBrowser4.SetFocus(1); // commented out to prevent crash
        }

        else if (pathBtn.GetState() == STATE_CLICKED) {
            w.Remove(&optionBrowser4);
            w.Remove(&backBtn);
            w.Remove(&pathBtn);
            w.Remove(&defaultBtn);
            char entered[43] = "";
            strlcpy(entered, Settings.languagefiles_path, sizeof(entered));
            int result = OnScreenKeyboard(entered,43,0);
            w.Append(&optionBrowser4);
            w.Append(&pathBtn);
            w.Append(&backBtn);
            w.Append(&defaultBtn);
            if ( result == 1 ) {
                int len = (strlen(entered)-1);
                if (entered[len] !='/')
                    strncat (entered, "/", 1);
                strlcpy(Settings.languagefiles_path, entered, sizeof(Settings.languagefiles_path));
                WindowPrompt(tr("Languagepath changed."),0,tr("OK"));
                if (isInserted(bootDevice)) {
                    cfg_save_global();
                    returnhere = 1;
                    break;
                } else {
                    WindowPrompt(tr("No SD-Card inserted!"), tr("Insert an SD-Card to save."), tr("OK"));
                }
            }
            if (countfiles > 0) {
                optionBrowser4.SetFocus(1);
            }
            pathBtn.ResetState();
        }

        ret = optionBrowser4.GetClickedOption();

        if (ret>=0) {
            choice = WindowPrompt(tr("Do you want to change language?"), 0, tr("Yes"), tr("Cancel"));
            if (choice == 1) {
                if (isInserted(bootDevice)) {
                    snprintf(Settings.language_path, sizeof(Settings.language_path), "%s%s", Settings.languagefiles_path, GetFileName(ret));
                    cfg_save_global();
                    if (!checkfile(Settings.language_path)) {
                        sprintf(Settings.language_path, tr("not set"));
                        WindowPrompt(tr("File not found."),tr("Loading standard language."),tr("OK"));
                    }
                    gettextCleanUp();
					HaltGui();
					CFG_Load();
					ResumeGui();
                    returnhere = 2;
                    break;
                } else {
                    WindowPrompt(tr("No SD-Card inserted!"), tr("Insert an SD-Card to save."), tr("OK"), 0,0,0,-1);
                }
            }
            optionBrowser4.SetFocus(1);
        }

    }

    w.SetEffect(EFFECT_FADE, -20);
    while (w.GetEffect()>0) usleep(50);

    HaltGui();
    mainWindow->Remove(&w);
    ResumeGui();

    return returnhere;
}
void Explorer::ProcessArcChoice(int choice, const char * destCandidat)
{
	ArchiveBrowser * browser = (ArchiveBrowser *) curBrowser;
	if(!browser)
		return;

	if(choice == ArcPasteItems)
	{
		int ret = WindowPrompt(tr("Paste the item(s) into this directory?"), Clipboard::Instance()->GetItemName(Clipboard::Instance()->GetItemcount()-1), tr("Yes"), tr("Cancel"));
		if(ret <= 0)
			return;

		PackTask *task = new PackTask(Clipboard::Instance(), browser->GetCurrentPath(), browser->GetArchive(), Settings.CompressionLevel);
		task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
		this->explorerTasks++;
		Taskbar::Instance()->AddTask(task);
		ThreadedTaskHandler::Instance()->AddTask(task);

		Clipboard::Instance()->Reset();
	}

	else if(choice == ArcExtractFile)
	{
		int ret = WindowPrompt(tr("Extract the selected item(s)?"), browser->GetCurrentName(), tr("Yes"), tr("Cancel"));
		if(ret <= 0)
			return;

		char dest[MAXPATHLEN];
		snprintf(dest, sizeof(dest), "%s", destCandidat);

		int result = OnScreenKeyboard(dest, sizeof(dest));
		if(result)
		{
			//append selected Item
			browser->MarkCurrentItem();
			//Get ItemMarker
			ItemMarker * IMarker = browser->GetItemMarker();
			//switch between browser index and archive file index
			for(int i = 0; i < IMarker->GetItemcount(); i++)
				IMarker->GetItem(i)->itemindex = browser->GetItemStructure(IMarker->GetItem(i)->itemindex)->fileindex;

			UnpackTask *task = new UnpackTask(IMarker, dest, browser->GetArchive(), false);
			task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
			this->explorerTasks++;
			Taskbar::Instance()->AddTask(task);
			ThreadedTaskHandler::Instance()->AddTask(task);

			IMarker->Reset();
		}
	}
	else if(choice == ArcExtractAll)
	{
		int ret = WindowPrompt(tr("Extract full archive?"), 0, tr("Yes"), tr("Cancel"));
		if(ret <= 0)
			return;

		char dest[MAXPATHLEN];
		snprintf(dest, sizeof(dest), "%s", destCandidat);
		if(dest[strlen(dest)-1] != '/')
			strcat(dest, "/");

		strncat(dest, browser->GetArchiveName(), sizeof(dest));

		char * ext = strrchr(dest, '.');
		if(ext)
			ext[0] = 0;
		strcat(dest, "/");

		int result = OnScreenKeyboard(dest, sizeof(dest));
		if(result)
		{
			UnpackTask *task = new UnpackTask(browser->GetItemMarker(), dest, browser->GetArchive(), true);
			task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
			this->explorerTasks++;
			Taskbar::Instance()->AddTask(task);
			ThreadedTaskHandler::Instance()->AddTask(task);

			browser->GetItemMarker()->Reset();
		}
	}
	else if(choice == ArcProperties)
	{
		browser->MarkCurrentItem();
		ItemMarker * Marker = browser->GetItemMarker();

		ArchiveProperties * Prompt = new ArchiveProperties(browser->GetArchive(), Marker);
		Prompt->SetAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
		Prompt->DimBackground(true);
		Application::Instance()->SetUpdateOnly(Prompt);
		Application::Instance()->Append(Prompt);

		Marker->Reset();
	}
}
void Explorer::ProcessChoice(int choice)
{
	FileBrowser * browser = (FileBrowser *) curBrowser;
	if(!browser)
		return;

	else if(browser->GetCurrentFilename() && strcmp(browser->GetCurrentFilename(),"..") != 0)
	{
		if(choice == CUT)
		{
			choice = WindowPrompt(browser->GetCurrentFilename(), tr("Cut current marked item(s)?"), tr("Yes"), tr("Cancel"));
			if(choice == 1)
			{
				Clipboard::Instance()->Reset();
				//append selected Item
				browser->MarkCurrentItem();
				//Get ItemMarker
				ItemMarker * IMarker = browser->GetItemMarker();

				for(int i = 0; i < IMarker->GetItemcount(); i++)
					Clipboard::Instance()->AddItem(IMarker->GetItem(i));

				IMarker->Reset();
				Clipboard::Instance()->Operation = OP_MOVE;
			}
		}

		else if(choice == COPY)
		{
			choice = WindowPrompt(browser->GetCurrentFilename(), tr("Copy current marked item(s)?"), tr("Yes"), tr("Cancel"));
			if(choice == 1)
			{
				Clipboard::Instance()->Reset();
				//append selected Item
				browser->MarkCurrentItem();
				//Get ItemMarker
				ItemMarker * IMarker = browser->GetItemMarker();

				for(int i = 0; i < IMarker->GetItemcount(); i++)
					Clipboard::Instance()->AddItem(IMarker->GetItem(i));

				IMarker->Reset();
				Clipboard::Instance()->Operation = OP_COPY;
			}
		}

		else if(choice == RENAME)
		{
			char srcpath[MAXPATHLEN];
			char destdir[MAXPATHLEN];
			snprintf(srcpath, sizeof(srcpath), "%s", browser->GetCurrentSelectedFilepath());
			char entered[151];
			snprintf(entered, sizeof(entered), "%s", browser->GetCurrentFilename());
			int result = OnScreenKeyboard(entered, 150);
			if(result == 1)
			{
				snprintf(destdir, sizeof(destdir), "%s/%s", browser->GetCurrentPath(), entered);
				if(!RenameFile(srcpath, destdir))
					WindowPrompt(tr("Failed renaming item"), tr("Name might already exists."), tr("OK"));
				//! Update browser
				guiBrowser->Refresh();
			}
		}

		else if(choice == DELETE)
		{
			char currentpath[MAXPATHLEN];
			snprintf(currentpath, sizeof(currentpath), "%s/", browser->GetCurrentSelectedFilepath());
			choice = WindowPrompt(browser->GetCurrentFilename(), tr("Delete the selected item(s) and its content?"), tr("Yes"), tr("Cancel"));
			if(choice == 1)
			{
				if(ProgressWindow::Instance()->IsRunning())
					choice = WindowPrompt(tr("Currently a process is running."), tr("Do you want to append this delete to the queue?"), tr("Yes"), tr("Cancel"));

				if(choice == 1)
				{
					//append selected Item
					browser->MarkCurrentItem();
					//Get ItemMarker
					ItemMarker * IMarker = browser->GetItemMarker();
					DeleteTask *task = new DeleteTask(IMarker);
					task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
					this->explorerTasks++;
					Taskbar::Instance()->AddTask(task);
					ThreadedTaskHandler::Instance()->AddTask(task);
					IMarker->Reset();
				}
			}
		}
	}
	else if(choice >= 0 && choice != PASTE && choice != NEWFOLDER && choice != PROPERTIES)
		WindowPrompt(tr("You cant use this operation on:"), tr("Directory .."), tr("OK"));

	if(choice == PASTE)
	{
		choice = WindowPrompt(Clipboard::Instance()->GetItemName(Clipboard::Instance()->GetItemcount()-1), tr("Paste item(s) into current directory?"), tr("Yes"), tr("Cancel"));
		if(choice == 1)
		{
			if(ProgressWindow::Instance()->IsRunning())
				choice = WindowPrompt(tr("Currently a process is running."), tr("Do you want to append this paste to the queue?"), tr("Yes"), tr("Cancel"));

			if(choice == 1)
			{
				if(Clipboard::Instance()->Operation == OP_COPY)
				{
					CopyTask *task = new CopyTask(Clipboard::Instance(), browser->GetCurrentPath());
					task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
					this->explorerTasks++;
					Taskbar::Instance()->AddTask(task);
					ThreadedTaskHandler::Instance()->AddTask(task);
				}
				else if(Clipboard::Instance()->Operation == OP_MOVE)
				{
					MoveTask *task = new MoveTask(Clipboard::Instance(), browser->GetCurrentPath());
					task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
					this->explorerTasks++;
					Taskbar::Instance()->AddTask(task);
					ThreadedTaskHandler::Instance()->AddTask(task);
				}
			}
		}
	}

	else if(choice == ADDTOZIP)
	{
		int ret = WindowPrompt(browser->GetCurrentFilename(), tr("Would you like to add/append the selected item(s) to a zip?"), tr("Yes"), tr("No"));
		if(ret <= 0)
			return;

		char DestZipPath[MAXPATHLEN];
		snprintf(DestZipPath, sizeof(DestZipPath), "%s", browser->GetCurrentPath());
		if(DestZipPath[strlen(DestZipPath)-1] != '/')
			strncat(DestZipPath, "/", sizeof(DestZipPath));
		strncat(DestZipPath, tr("NewZip.zip"), sizeof(DestZipPath));

		if(!OnScreenKeyboard(DestZipPath, sizeof(DestZipPath)))
			return;

		std::string DestPath = DestZipPath;
		size_t pos = DestPath.rfind('/');
		if(pos != std::string::npos)
			DestPath.erase(pos);

		CreateSubfolder(DestPath.c_str());

		//append selected Item
		browser->MarkCurrentItem();
		//Get ItemMarker
		ItemMarker * IMarker = browser->GetItemMarker();

		ZipFile *Zip = new ZipFile(DestZipPath, CheckFile(DestZipPath) ? ZipFile::APPEND : ZipFile::CREATE);
		ArchiveHandle * archive = new ArchiveHandle(Zip);

		PackTask *task = new PackTask(IMarker, "", archive, Settings.CompressionLevel);
		task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
		this->explorerTasks++;
		Taskbar::Instance()->AddTask(task);
		ThreadedTaskHandler::Instance()->AddTask(task);

		//! Update browser
		IMarker->Reset();
	}

	else if(choice == CHECK_MD5)
	{
		int md5Choice = 1;

		if(ProgressWindow::Instance()->IsRunning())
			md5Choice = WindowPrompt(tr("Currently a process is running."), tr("Do you want to append this process to the queue?"), tr("Yes"), tr("Cancel"));

		if(md5Choice == 1)
		{
			char LogPath[1024];
			snprintf(LogPath, sizeof(LogPath), "%s/MD5.log", browser->GetCurrentPath());

			browser->MarkCurrentItem();
			MD5Task *task = new MD5Task(browser->GetItemMarker(), LogPath);
			task->TaskEnd.connect(this, &Explorer::OnFinishedTask);
			this->explorerTasks++;
			Taskbar::Instance()->AddTask(task);
			ThreadedTaskHandler::Instance()->AddTask(task);
			browser->GetItemMarker()->Reset();
		}
	}

	else if(choice == NEWFOLDER)
	{
		char entered[151];
		snprintf(entered, sizeof(entered), tr("New Folder"));
		int result = OnScreenKeyboard(entered, 150);
		if(result == 1)
		{
			char currentpath[MAXPATHLEN];
			snprintf(currentpath, sizeof(currentpath), "%s/%s/", browser->GetCurrentPath(), entered);
			bool ret = CreateSubfolder(currentpath);
			if(ret == false)
				ShowError(tr("Unable to create folder."));

			//! Update browser
			guiBrowser->Refresh();
		}
	}
	else if(choice == PROPERTIES)
	{
		browser->MarkCurrentItem();
		ItemMarker * Marker = browser->GetItemMarker();
		Properties * Prompt = new Properties(Marker);
		Prompt->SetAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
		Prompt->DimBackground(true);
		Application::Instance()->SetUpdateOnly(Prompt);
		Application::Instance()->Append(Prompt);
		Marker->Reset();
	}
}
Example #5
0
bool GuiBrowser(GuiWindow *mainWindow, GuiWindow *parentWindow, char *path, const char *label)
{
    char temp[256];
    char title[100];
	int i;

	ShutoffRumble();

	// populate initial directory listing
	if(BrowseDevice() <= 0)
	{
		WindowPrompt(
		"Error",
		"Unable to display files on selected load device",
		"Ok",
		NULL);

        return false;
	}

	int menu = MENU_NONE;
	int dev = 0;
	char mount[2][5] = {"SD", "USB"};

    GuiTrigger trigA;
	trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);

    if(OpenDefaultFolder() <= 0)
    {
        BrowseDevice();
        bzero(temp, sizeof(temp));
    }
    else sprintf(temp, "%s/", Settings.UserFolder);

	sprintf(title, "Browse files");
	bzero(path, sizeof(path));

    GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
    GuiImageData Textbox(textbox_end_png);
    GuiImage TextboxImg(&Textbox);
    GuiButton InsertURL(TextboxImg.GetWidth(), TextboxImg.GetHeight());

    GuiImageData Device(textbox_begin_png);
    GuiImage DeviceImg(&Device);
    GuiButton InsertDEV(DeviceImg.GetWidth(), DeviceImg.GetHeight());

    GuiText URL(strchr(temp, '/'), 20, (GXColor){0, 0, 0, 255});
    GuiText DEV("SD", 20, (GXColor){0, 0, 0, 255});

    URL.SetMaxWidth(TextboxImg.GetWidth()-20);
    URL.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
    URL.SetPosition(5,0);
    URL.SetScroll(SCROLL_HORIZONTAL);

    InsertURL.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    InsertURL.SetPosition(InsertDEV.GetWidth()/2,30);
    InsertURL.SetLabel(&URL);
    InsertURL.SetImage(&TextboxImg);
    InsertURL.SetSoundOver(&btnSoundOver);
    InsertURL.SetTrigger(&trigA);

    InsertDEV.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    InsertDEV.SetPosition(InsertURL.GetLeft()-InsertDEV.GetWidth()/2,30);
    InsertDEV.SetLabel(&DEV);
    InsertDEV.SetImage(&DeviceImg);
    InsertDEV.SetSoundOver(&btnSoundOver);
    InsertDEV.SetTrigger(&trigA);
    InsertDEV.SetEffectGrow();

    GuiText titleTxt(title, 28, (GXColor){0, 0, 0, 255});
    titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
	titleTxt.SetPosition(50,50);

	GuiFileBrowser fileBrowser(552, 248);
	fileBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
	fileBrowser.SetPosition(0, 108);
	fileBrowser.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 30);

	GuiImageData btnOutline(button_png);
	GuiImageData btnOutlineOver(button_over_png);

	GuiText okBtnTxt(label, 24, (GXColor){0, 0, 0, 255});
	GuiImage okBtnImg(&btnOutline);
	GuiImage okBtnImgOver(&btnOutlineOver);
	GuiButton okBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
	okBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
	okBtn.SetPosition(50, -35);
	okBtn.SetLabel(&okBtnTxt);
	okBtn.SetImage(&okBtnImg);
	okBtn.SetImageOver(&okBtnImgOver);
	okBtn.SetTrigger(&trigA);
	okBtn.SetEffectGrow();

    GuiText cancelBtnTxt("Cancel", 24, (GXColor){0, 0, 0, 255});
	GuiImage cancelBtnImg(&btnOutline);
	GuiImage cancelBtnImgOver(&btnOutlineOver);
	GuiButton cancelBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
	cancelBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
	cancelBtn.SetPosition(-50, -35);
	cancelBtn.SetLabel(&cancelBtnTxt);
	cancelBtn.SetImage(&cancelBtnImg);
	cancelBtn.SetImageOver(&cancelBtnImgOver);
	cancelBtn.SetTrigger(&trigA);
	cancelBtn.SetEffectGrow();

	GuiWindow buttonWindow(screenwidth, screenheight);
	buttonWindow.Append(&okBtn);
	buttonWindow.Append(&cancelBtn);
	buttonWindow.Append(&InsertURL);
	buttonWindow.Append(&InsertDEV);
    buttonWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 30);

    if (mainWindow)
    {
        mainWindow->SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
        while(mainWindow->GetEffect() > 0)
            usleep(100);
    }

    HaltGui();
    if (mainWindow)
        parentWindow->Remove(mainWindow);
    parentWindow->Append(&buttonWindow);
    parentWindow->Append(&fileBrowser);
    ResumeGui();

	while(menu == MENU_NONE)
	{
		usleep(100);
		if(!strlen(URL.GetText()) || URL.GetText()[0] != '/')
        {
            sprintf(temp, "%s", rootdir);
            URL.SetText(strchr(temp, '/'));
        }

        if(InsertURL.GetState() == STATE_CLICKED)
        {
            URL.SetScroll(SCROLL_NONE);
            OnScreenKeyboard(parentWindow, strchr(temp, '/'), 256);
            URL.SetText(strchr(temp, '/'));
            URL.SetScroll(SCROLL_HORIZONTAL);

            InsertURL.ResetState();
        }

        if(InsertDEV.GetState() == STATE_CLICKED)
        {
            InsertDEV.ResetState();
            dev ^= 1;

            if(BrowseDevice(dev) <= 0)
            {
                BrowseDevice();
                dev = 0;
            }

            DEV.SetText(mount[dev]);
            URL.SetText("");
        }

		// update file browser based on arrow buttons
		// set MENU_EXIT if A button pressed on a file
		for(i=0; i < FILE_PAGESIZE; i++)
		{
			if(fileBrowser.fileList[i]->GetState() == STATE_CLICKED)
			{
				fileBrowser.fileList[i]->ResetState();
				// check corresponding browser entry
				if(browserList[browser.selIndex].isdir)
				{
					if(BrowserChangeFolder())
					{
						fileBrowser.ResetState();
						fileBrowser.fileList[0]->SetState(STATE_SELECTED);
						fileBrowser.TriggerUpdate();

                        if(strlen(browser.dir) > 1)
                            sprintf(fullpath, "%s%s/", rootdir, browser.dir+1); // print current path
                        else sprintf(fullpath, "%s", rootdir); // print current path

                        sprintf(temp, fullpath);
                        URL.SetText(strchr(temp, '/'));
					}
					else
					{
						menu = MENU_HOME;
						break;
					}
				}
				else
				{
					ShutoffRumble();
					// load file
					if(strlen(browser.dir) > 1)
                        sprintf(fullpath, "%s%s/%s", rootdir, browser.dir+1, browserList[browser.selIndex].filename); // print current path
                    else sprintf(fullpath, "%s%s", rootdir, browserList[browser.selIndex].filename); // print current path

                    sprintf(temp, fullpath);
                    URL.SetText(strchr(temp, '/'));
				}
			}
		}

		if(okBtn.GetState() == STATE_CLICKED)
		{
		    sprintf(path, temp);
		    menu = MENU_HOME;
		}
        if(cancelBtn.GetState() == STATE_CLICKED)
		    menu = MENU_HOME;
	}

    fileBrowser.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50);
    buttonWindow.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50);
    while(buttonWindow.GetEffect() > 0)
        usleep(100);

    fileBrowser.SetVisible(false);
    buttonWindow.SetVisible(false);

    if(mainWindow)
    {
        mainWindow->SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 30);
        parentWindow->Append(mainWindow);
        while(mainWindow->GetEffect() > 0)
            usleep(100);
    }

    HaltGui();
    parentWindow->Remove(&buttonWindow);
    parentWindow->Remove(&fileBrowser);
    ResumeGui();

    if (isValidPath(path))
        return true;
    return false;
}
Example #6
0
static int MenuSettingsFile() {
    int menu = MENU_NONE;
    int ret;
    int i = 0;
    bool firstRun = true;
    OptionList options;
    sprintf(options.name[i++], "Load Device");
    sprintf(options.name[i++], "Save Device");
    sprintf(options.name[i++], "Folder 1");
    sprintf(options.name[i++], "Folder 2");
    sprintf(options.name[i++], "Folder 3");
    sprintf(options.name[i++], "Auto Load");
    sprintf(options.name[i++], "Auto Save");
    options.length = i;

    GuiText titleTxt("Settings - Saving & Loading", 28, ColorGrey);
    titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
    titleTxt.SetPosition(50, 50);

    GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM);
    GuiImageData btnOutline(xenon_button_png);
    GuiImageData btnOutlineOver(xenon_button_over_png);

    GuiTrigger trigA;
    //	trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
    trigA.SetSimpleTrigger(-1, 0, PAD_BUTTON_A);

    GuiText backBtnTxt("Go Back", 22, ColorGrey2);
    GuiImage backBtnImg(&btnOutline);
    GuiImage backBtnImgOver(&btnOutlineOver);
    GuiButton backBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
    backBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
    backBtn.SetPosition(100, -35);
    backBtn.SetLabel(&backBtnTxt);
    backBtn.SetImage(&backBtnImg);
    backBtn.SetImageOver(&backBtnImgOver);
    backBtn.SetSoundOver(&btnSoundOver);
    backBtn.SetTrigger(&trigA);
    backBtn.SetEffectGrow();

    GuiOptionBrowser optionBrowser(552, 248, &options);
    optionBrowser.SetPosition(0, 108);
    optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
    optionBrowser.SetCol2Position(185);

    HaltGui();
    GuiWindow w(screenwidth, screenheight);
    w.Append(&backBtn);
    mainWindow->Append(&optionBrowser);
    mainWindow->Append(&w);
    mainWindow->Append(&titleTxt);
    ResumeGui();

    while (menu == MENU_NONE) {
        UGUI();
        usleep(THREAD_SLEEP);

        ret = optionBrowser.GetClickedOption();

        switch (ret) {
            case 0:
                Settings.LoadMethod++;
                break;

            case 1:
                Settings.SaveMethod++;
                break;

            case 2:
                OnScreenKeyboard(Settings.Folder1, 256);
                break;

            case 3:
                OnScreenKeyboard(Settings.Folder2, 256);
                break;

            case 4:
                OnScreenKeyboard(Settings.Folder3, 256);
                break;

            case 5:
                Settings.AutoLoad++;
                if (Settings.AutoLoad > 2)
                    Settings.AutoLoad = 0;
                break;

            case 6:
                Settings.AutoSave++;
                if (Settings.AutoSave > 3)
                    Settings.AutoSave = 0;
                break;
        }

        if (ret >= 0 || firstRun) {
            firstRun = false;

            // correct load/save methods out of bounds
            if (Settings.LoadMethod > 4)
                Settings.LoadMethod = 0;
            if (Settings.SaveMethod > 6)
                Settings.SaveMethod = 0;

            if (Settings.LoadMethod == METHOD_AUTO) sprintf(options.value[0], "Auto Detect");
            else if (Settings.LoadMethod == METHOD_SD) sprintf(options.value[0], "SD");
            else if (Settings.LoadMethod == METHOD_USB) sprintf(options.value[0], "USB");
            else if (Settings.LoadMethod == METHOD_DVD) sprintf(options.value[0], "DVD");
            else if (Settings.LoadMethod == METHOD_SMB) sprintf(options.value[0], "Network");

            if (Settings.SaveMethod == METHOD_AUTO) sprintf(options.value[1], "Auto Detect");
            else if (Settings.SaveMethod == METHOD_SD) sprintf(options.value[1], "SD");
            else if (Settings.SaveMethod == METHOD_USB) sprintf(options.value[1], "USB");
            else if (Settings.SaveMethod == METHOD_SMB) sprintf(options.value[1], "Network");
            else if (Settings.SaveMethod == METHOD_MC_SLOTA) sprintf(options.value[1], "MC Slot A");
            else if (Settings.SaveMethod == METHOD_MC_SLOTB) sprintf(options.value[1], "MC Slot B");

            snprintf(options.value[2], 256, "%s", Settings.Folder1);
            snprintf(options.value[3], 256, "%s", Settings.Folder2);
            snprintf(options.value[4], 256, "%s", Settings.Folder3);

            if (Settings.AutoLoad == 0) sprintf(options.value[5], "Off");
            else if (Settings.AutoLoad == 1) sprintf(options.value[5], "Some");
            else if (Settings.AutoLoad == 2) sprintf(options.value[5], "All");

            if (Settings.AutoSave == 0) sprintf(options.value[5], "Off");
            else if (Settings.AutoSave == 1) sprintf(options.value[6], "Some");
            else if (Settings.AutoSave == 2) sprintf(options.value[6], "All");

            optionBrowser.TriggerUpdate();
        }

        if (backBtn.GetState() == STATE_CLICKED) {
            menu = MENU_SETTINGS;
        }

    }
    HaltGui();
    mainWindow->Remove(&optionBrowser);
    mainWindow->Remove(&w);
    mainWindow->Remove(&titleTxt);
    return menu;
}