mirror of
https://github.com/sheumann/DiskBrowser.git
synced 2024-11-25 17:43:15 +00:00
Search for disks based on the query string.
This commit is contained in:
parent
19b00980c9
commit
827dc6fefe
@ -18,6 +18,7 @@
|
|||||||
#include <finder.h>
|
#include <finder.h>
|
||||||
#include <tcpip.h>
|
#include <tcpip.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "mounturl.h"
|
#include "mounturl.h"
|
||||||
#include "seturl.h"
|
#include "seturl.h"
|
||||||
@ -62,7 +63,12 @@ Boolean resourceFileOpened, windowOpened;
|
|||||||
/* User preference */
|
/* User preference */
|
||||||
boolean gsDisksOnly = true;
|
boolean gsDisksOnly = true;
|
||||||
|
|
||||||
#define DISK_LIST_LENGTH 10
|
char queryBuf[257];
|
||||||
|
#define queryString (queryBuf + 1)
|
||||||
|
|
||||||
|
int pageNum = 0;
|
||||||
|
|
||||||
|
#define DISK_LIST_LENGTH 30
|
||||||
|
|
||||||
struct diskListEntry {
|
struct diskListEntry {
|
||||||
char *memPtr;
|
char *memPtr;
|
||||||
@ -195,17 +201,41 @@ boolean processDoc(json_value *docObj) {
|
|||||||
if (id == NULL || title == NULL)
|
if (id == NULL || title == NULL)
|
||||||
return true;
|
return true;
|
||||||
diskList[diskListPos].idPtr = id->u.string.ptr;
|
diskList[diskListPos].idPtr = id->u.string.ptr;
|
||||||
|
// TODO character set translation
|
||||||
diskList[diskListPos++].memPtr = title->u.string.ptr;
|
diskList[diskListPos++].memPtr = title->u.string.ptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do a search */
|
/* Do a search */
|
||||||
void DoSearch(void) {
|
void DoSearch(void) {
|
||||||
static char searchURL[] = "http://archive.org/advancedsearch.php?q=emulator%3Aapple3&fl%5B%5D=identifier&fl%5B%5D=title&rows=3&page=1&output=json";
|
char *searchURL = NULL;
|
||||||
|
int urlLength = 0;
|
||||||
enum NetDiskError result;
|
enum NetDiskError result;
|
||||||
|
|
||||||
WaitCursor();
|
WaitCursor();
|
||||||
|
|
||||||
|
GetLETextByID(window, searchLine, (StringPtr)&queryBuf);
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
urlLength = snprintf(searchURL, urlLength,
|
||||||
|
"http://archive.org/advancedsearch.php?"
|
||||||
|
"q=emulator%%3A%s%%20%s"
|
||||||
|
"&fl%%5B%%5D=identifier&fl%%5B%%5D=title"
|
||||||
|
"&fl%%5B%%5D=emulator_ext"
|
||||||
|
"&rows=%i&page=%i&output=json",
|
||||||
|
gsDisksOnly ? "apple2gs" : "apple2*",
|
||||||
|
queryString,
|
||||||
|
DISK_LIST_LENGTH,
|
||||||
|
pageNum);
|
||||||
|
if (urlLength <= 0)
|
||||||
|
goto errorReturn;
|
||||||
|
if (i == 0) {
|
||||||
|
searchURL = malloc(urlLength);
|
||||||
|
if (searchURL == NULL)
|
||||||
|
goto errorReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = SetURL(&sess, searchURL, FALSE, FALSE);
|
result = SetURL(&sess, searchURL, FALSE, FALSE);
|
||||||
//TODO enable this once we have real code to build the URL
|
//TODO enable this once we have real code to build the URL
|
||||||
//if (result != OPERATION_SUCCESSFUL)
|
//if (result != OPERATION_SUCCESSFUL)
|
||||||
@ -265,11 +295,13 @@ void DoSearch(void) {
|
|||||||
ShowControl(GetCtlHandleFromID(window, ofPagesText));
|
ShowControl(GetCtlHandleFromID(window, ofPagesText));
|
||||||
ShowControl(GetCtlHandleFromID(window, nextPageButton));
|
ShowControl(GetCtlHandleFromID(window, nextPageButton));
|
||||||
|
|
||||||
|
free(searchURL);
|
||||||
EndTCPConnection(&sess);
|
EndTCPConnection(&sess);
|
||||||
InitCursor();
|
InitCursor();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
errorReturn:
|
errorReturn:
|
||||||
|
free(searchURL);
|
||||||
EndTCPConnection(&sess);
|
EndTCPConnection(&sess);
|
||||||
InitCursor();
|
InitCursor();
|
||||||
// TODO show error message
|
// TODO show error message
|
||||||
|
Loading…
Reference in New Issue
Block a user