Make linux installer localizable. [nsbeta3+ b=2288; r=dbragg;dveditz]

This commit is contained in:
sgehani%netscape.com 2000-09-14 05:15:46 +00:00
Родитель f326039fe4
Коммит 029610f199
17 изменённых файлов: 443 добавлений и 209 удалений

Просмотреть файл

@ -31,7 +31,7 @@ include $(DEPTH)/config/autoconf.mk
PROGRAM = mozilla-installer-bin
CPPSRCS = \
XIErrors.cpp \
nsINIParser.cpp \
nsFTPConn.cpp \
nsXInstallerDlg.cpp \
nsComponent.cpp \
@ -48,7 +48,6 @@ CPPSRCS = \
nsXIContext.cpp \
nsXInstaller.cpp \
nsXIEngine.cpp \
nsINIParser.cpp \
$(NULL)
LIBS = \

Просмотреть файл

@ -28,38 +28,6 @@
#include "XIErrors.h"
#include <gtk/gtk.h>
/*--------------------------------------------------------------------*
* Default Strings
*--------------------------------------------------------------------*/
#define NEXT "Next >"
#define BACK "< Back"
#define CANCEL "Cancel"
#define ACCEPT "Accept"
#define DECLINE "Decline"
#define INSTALL "Install"
#define DEFAULT_TITLE "Mozilla Installer"
#define DEST_DIR "Destination Directory"
#define BROWSE "Change..."
#define SELECT_DIR "Select a directory"
#define DOESNT_EXIST "Directory %s doesn't exist. Create it?\n"
#define YES_LABEL "Yes"
#define NO_LABEL "No"
#define OK_LABEL "OK"
#define DELETE_LABEL "Delete"
#define CANCEL_LABEL "Cancel"
#define ERROR "Error [%d]: %s\n"
#define FATAL_ERROR "Fatal error [%d]: %s\n"
#define WARNING "Warning [%d]: %s\n"
#define DESCRIPTION "Description"
#define DOWNLOADING "Downloading %s [%d/%d]"
#define DLRATE " at %d K/sec..."
#define PREPARING "Preparing %s..."
#define EXTRACTING "Extracting %s..."
#define INSTALLING_XPI "Installing %s..."
#define PROCESSING_FILE "Processing file %d of %d..."
#define EXTRACTING_FILES "Extracting files..."
#define COMPLETED "Installation has completed."
/*--------------------------------------------------------------------*
* Limits

Просмотреть файл

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*/
#include "XIErrors.h"
#include "XIDefines.h"
static GtkWidget *sErrDlg;
static char *ERRORS[] = {
"___ACCOUNT_FOR_ZERO_INDEX___",
"Out of memory",
"Invalid param",
"Invalid member variable",
"Invalid pointer",
"Parse key has no value",
"Failed to read readme",
"Failed to read license",
"Out of bounds in Component/Setup Type list",
"Mismatched ref counts",
"No components in the INI file",
"No setup types in the INI file",
"URL at this index already exists",
"Couldn't create the directory",
"FTP URL malformed",
"Download failed",
"Extraction of XPCOM failed",
"Failed to fork a process",
"Couldn't open xpistub library",
"Couldn't get symbol in library",
"A xpistub call failed",
"A .xpi failed to install",
"Copy of a .xpi failed",
"Destination directory doesn't exist",
"Can't make destination directory. Please try another directory.",
"___PREVENT_FALLING_OF_END___"
};
/*------------------------------------------------------------------*
* Default Error Handler
*------------------------------------------------------------------*/
int
ErrorHandler(int aErr)
{
GtkWidget *okButton, *label;
char msg[256];
int resNum;
resNum = -1 * (aErr % 100);
if (aErr < FATAL_ERR_THRESHOLD)
sprintf(msg, FATAL_ERROR, aErr, ERRORS[resNum]);
else if (aErr < GENERAL_ERR_THRESHOLD)
sprintf(msg, ERROR, aErr, ERRORS[resNum]);
else
{
printf(msg, WARNING, aErr, ERRORS[resNum]);
return aErr;
}
sErrDlg = gtk_dialog_new();
okButton = gtk_button_new_with_label(OK_LABEL);
label = gtk_label_new(msg);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sErrDlg)->action_area),
okButton);
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
GTK_SIGNAL_FUNC(ErrDlgOK), (void*)aErr);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sErrDlg)->vbox), label);
gtk_widget_show_all(sErrDlg);
return aErr;
}
void
ErrDlgOK(GtkWidget *aWidget, gpointer aData)
{
int err = (int) aData;
gtk_widget_destroy(sErrDlg);
if (err < FATAL_ERR_THRESHOLD)
exit(err);
}

Просмотреть файл

@ -57,18 +57,12 @@
E_FORK_FAILED = -617, /* failed to fork a process */
E_LIB_OPEN = -618, /* couldn't open stub lib */
E_LIB_SYM = -619, /* couldn't get symbol in lib */
E_XPI_FAIL = -420, /* a xpistub call failed */
E_INSTALL = -421, /* a .xpi failed to install */
E_XPI_FAIL = -620, /* a xpistub call failed */
E_INSTALL = -621, /* a .xpi failed to install */
E_CP_FAIL = -622, /* copy of a xpi failed */
E_NO_DEST = -623, /* destination dir doesn't exist */
E_MKDIR_FAIL = -424, /* can't make destination dir */
E_OLD_INST = -425 /* old instllation exists */
E_MKDIR_FAIL = -624, /* can't make destination dir */
E_OLD_INST = -625 /* old instllation exists */
};
#define FATAL_ERR_THRESHOLD -500 /* errs below this cause app quit */
#define GENERAL_ERR_THRESHOLD -1 /* errs below this cause dlg to come up*/
int ErrorHandler(int aErr);
void ErrDlgOK(GtkWidget *aWidget, gpointer aData);
#endif /* _XI_ERRORS_H_ */

Просмотреть файл

@ -10,7 +10,7 @@ Title=Le Mozilla Installer
;-------------------------------------------------------------------------
Show Dialog=TRUE
Title=Mozilla Installer
Readme File=README
Readme File=
;-------------------------------------------------------------------------

Просмотреть файл

@ -0,0 +1,64 @@
[String Resources]
;------------------------------------------------------------------------------
; UI strings
;------------------------------------------------------------------------------
NEXT=Next >
BACK=< Back
CANCEL=Cancel
ACCEPT=Accept
DECLINE=Decline
INSTALL=Install
DEFAULT_TITLE=Mozilla Installer
DEST_DIR=Destination Directory
BROWSE=Change...
SELECT_DIR=Select a directory
DOESNT_EXIST=Directory %s doesn't exist. Create it?
YES_LABEL=Yes
NO_LABEL=No
OK_LABEL=OK
DELETE_LABEL=Delete
CANCEL_LABEL=Cancel
ERROR=Error [%d]: %s
FATAL_ERROR=Fatal error [%d]: %s
DESCRIPTION=Description
DOWNLOADING=Downloading %s [%d/%d]
DLRATE= at %d K/sec...
PREPARING=Preparing %s...
EXTRACTING=Extracting %s...
INSTALLING_XPI=Installing %s...
PROCESSING_FILE=Processing file %d of %d...
COMPLETED=Installation has completed.
;------------------------------------------------------------------------------
; Error strings
;------------------------------------------------------------------------------
-601=Out of memory
-602=Invalid param
-603=Invalid member variable
-604=Invalid pointer
-605=Parse key has no value
-606=Failed to read readme
-607=Failed to read license
-608=Out of bounds in Component/Setup Type list
-609=Mismatched ref counts
-610=No components in the INI file
-611=No setup types in the INI file
-612=URL at this index already exists
-613=Couldn't create the directory
-614=FTP URL malformed
-615=Download failed
-616=Extraction of XPCOM failed
-617=Failed to fork a process
-618=Couldn't open xpistub library
-619=Couldn't get symbol in library
-620=A xpistub call failed
-621=An installer module (.xpi) failed to install
-622=Copy of an installer module (.xpi) failed
-623=Destination directory doesn't exist
-624=Can't make destination directory. Please try another directory.
-625=A previous installation exists.

Просмотреть файл

@ -357,7 +357,7 @@ nsComponentsDlg::Show(int aDirection)
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
20, 20);
frame = gtk_frame_new(DESCRIPTION);
frame = gtk_frame_new(gCtx->Res("DESCRIPTION"));
gtk_table_attach_defaults(GTK_TABLE(descLongTable), frame, 0, 1, 0, 1);
gtk_widget_show(frame);
@ -390,7 +390,7 @@ nsComponentsDlg::Show(int aDirection)
if (aDirection == nsXInstallerDlg::BACKWARD_MOVE) // from install dlg
{
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->installLabel);
gCtx->nextLabel = gtk_label_new(NEXT);
gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
gtk_widget_show(gCtx->nextLabel);
gtk_widget_show(gCtx->next);

Просмотреть файл

@ -41,7 +41,8 @@ nsFTPConn::nsFTPConn(char *aHost) :
mState(CLOSED),
mCntlFd(-1),
mDataFd(-1),
mEOFFound(FALSE)
mEOFFound(FALSE),
mPassive(FALSE)
{
}
@ -109,8 +110,6 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite,
int err = OK, connfd = 0, wrote = 0, totBytesRd = 0;
char cmd[CMD_BUF_SIZE], resp[RESP_BUF_SIZE];
int fileSize = 0, respBufSize = RESP_BUF_SIZE;
socklen_t clilen;
struct sockaddr cliaddr;
FILE *loclfd = NULL;
if (!aSrvPath || !aLoclPath)
@ -125,9 +124,8 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite,
mState = GETTING;
// XXX rename to RawDataInit()
/* initialize data connection */
ERR_CHECK(RawListen(mHost, DATA_PORT, &mDataFd));
ERR_CHECK(RawDataInit(mHost, DATA_PORT, &mDataFd));
/* issue SIZE command on control connection */
sprintf(cmd, "SIZE %s\r\n", aSrvPath);
@ -143,15 +141,8 @@ nsFTPConn::Get(char *aSrvPath, char *aLoclPath, int aType, int aOvWrite,
sprintf(cmd, "RETR %s\r\n", aSrvPath);
ERR_CHECK(IssueCmd(cmd, resp, RESP_BUF_SIZE, mCntlFd));
// XXX move this to RawDataConnect()
/* get file contents on data connection */
clilen = sizeof(cliaddr);
connfd = accept(mDataFd, (struct sockaddr *) &cliaddr, &clilen);
if (connfd < 0)
{
err = E_ACCEPT;
goto BAIL;
}
ERR_CHECK(RawDataConnect(mDataFd, &connfd));
/* initialize locl file */
if (!(loclfd = fopen(aLoclPath, aType==BINARY ? "wb" : "w")) ||
@ -193,7 +184,8 @@ BAIL:
/* kill data connection if it exists */
if (mDataFd > 0)
{
RawClose(mDataFd);
if (!mPassive) /* for passive mDataFd==connfd so don't close twice! */
RawClose(mDataFd);
mDataFd = -1;
}
if (connfd > 0)
@ -206,6 +198,7 @@ BAIL:
}
mState = OPEN;
mPassive = FALSE;
return err;
}
@ -307,6 +300,9 @@ BAIL:
return err;
}
/*---------------------------------------------------------------------------*
* "Raw" transport primitives (port below here)
*---------------------------------------------------------------------------*/
int
nsFTPConn::RawConnect(char *aHost, int aPort, int *aFd)
{
@ -346,23 +342,41 @@ nsFTPConn::RawConnect(char *aHost, int aPort, int *aFd)
}
int
nsFTPConn::RawListen(char *aHost, int aPort, int *aFd)
nsFTPConn::RawDataInit(char *aHost, int aPort, int *aFd)
{
int err = OK;
struct sockaddr_in servaddr;
socklen_t salen;
int listenfd = 0;
char cmd[CMD_BUF_SIZE], resp[RESP_BUF_SIZE];
char *srvhost = NULL;
int srvport = 0;
/* param check */
if (!aHost || !aFd)
return E_PARAM;
// XXX TODO: handle PASV mode
// XXX * issue PASV command
// XXX * if passive command returns an error use active mode
// XXX * else connect to supplied port
/* issue PASV command */
sprintf(cmd, "PASV\r\n");
err = IssueCmd(cmd, resp, RESP_BUF_SIZE, mCntlFd);
if (err != OK)
{
err = OK;
goto ACTIVE; /* failover to active mode */
}
mPassive = TRUE;
ERR_CHECK(RawParseAddr(resp, &srvhost, &srvport));
ERR_CHECK(RawConnect(srvhost, srvport, &mDataFd));
if (srvhost)
free(srvhost);
srvhost = NULL;
return err;
ACTIVE:
/* init data socket making it listen */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
@ -394,6 +408,35 @@ nsFTPConn::RawListen(char *aHost, int aPort, int *aFd)
*aFd = listenfd;
BAIL:
if (mPassive && err != OK)
mPassive = FALSE;
return err;
}
int
nsFTPConn::RawDataConnect(int aDataFd, int *aConnFd)
{
int err = OK;
struct sockaddr cliaddr;
socklen_t clilen;
int connfd = 0;
if (!aConnFd)
return E_PARAM;
if (mPassive)
{
*aConnFd = aDataFd;
return OK;
}
clilen = sizeof(cliaddr);
connfd = accept(aDataFd, (struct sockaddr *) &cliaddr, &clilen);
if (connfd < 0)
err = E_ACCEPT;
*aConnFd = connfd;
return err;
}
@ -541,6 +584,43 @@ nsFTPConn::RawRecv(unsigned char *aBuf, int *aBufSize, int aFd)
return err;
}
int
nsFTPConn::RawParseAddr(char *aBuf, char **aHost, int *aPort)
{
int err = OK;
char *c;
int addr[6];
/* param check */
if (!aBuf || !aHost || !aPort)
return E_PARAM;
c = aBuf + strlen("227 "); /* pass by return code */
while (!isdigit((int)(*c)))
{
if (*c == '\0')
return E_INVALID_ADDR;
c++;
}
if (sscanf(c, "%d,%d,%d,%d,%d,%d",
&addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6)
return E_INVALID_ADDR;
*aHost = (char *)malloc(strlen("XXX.XXX.XXX.XXX"));
sprintf(*aHost, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
*aPort = ((addr[4] & 0xFF) << 8) | (addr[5] & 0xFF);
#ifdef DEBUG
printf("%s %d: PASV response: %d,%d,%d,%d,%d,%d\n", __FILE__, __LINE__,
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
printf("%s %d: Host = %s\tPort = %d\n", __FILE__, __LINE__, *aHost, *aPort);
#endif
return err;
}
#define KILOBYTE 1024
float
nsFTPConn::CalcRate(struct timeval *aPre, struct timeval *aPost, int aBytes)

Просмотреть файл

@ -31,6 +31,7 @@
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/time.h>
@ -98,26 +99,30 @@ public:
E_GETSOCKNAME = -818, /* getsockname() failed */
E_READ_MORE = 819, /* more to read from this socket */
E_LOCL_INIT = -820, /* local file open/init failed */
E_TIMEOUT = -821 /* select() timed out */
E_TIMEOUT = -821, /* select() timed out */
E_INVALID_ADDR = -822 /* couldn't parse address/port */
};
private:
int IssueCmd(char *aCmd, char *aResp, int aRespSize, int aFd);
/*--------------------------------------------------------------------*
* Platform-specific Impls
* "Raw" transport primitives
*--------------------------------------------------------------------*/
int RawConnect(char *aHost, int aPort, int *aFd); /* cli init */
int RawListen(char *aHost, int aPort, int *aFd); /* srv init */
int RawConnect(char *aHost, int aPort, int *aFd); /* cli init */
int RawDataInit(char *aHost, int aPort, int *aFd); /* srv init1 */
int RawDataConnect(int aDataFd, int *aConnFd); /* srv init2 */
int RawClose(int aFd);
int RawSend(unsigned char *aBuf, int *aBufSize, int aFd);
int RawRecv(unsigned char *aBuf, int *aBufSize, int aFd);
int RawParseAddr(char *aBuf, char **aHost, int *aPort);
char *mHost;
int mState;
int mCntlFd;
int mDataFd;
int mEOFFound;
int mPassive;
};
#ifndef NULL

Просмотреть файл

@ -250,7 +250,7 @@ nsInstallDlg::Show(int aDirection)
// always change title of next button to "Install"
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
gCtx->installLabel = gtk_label_new(INSTALL);
gCtx->installLabel = gtk_label_new(gCtx->Res("INSTALL"));
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->installLabel);
gtk_widget_show(gCtx->installLabel);
gtk_widget_show(gCtx->next);
@ -359,7 +359,7 @@ nsInstallDlg::XPIProgressCB(const char *aMsg, int aVal, int aMax)
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMinorProgBar), percent);
gtk_widget_show(sMinorProgBar);
sprintf(msg, PROCESSING_FILE, aVal, aMax);
sprintf(msg, gCtx->Res("PROCESSING_FILE"), aVal, aMax);
}
else
{
@ -413,15 +413,15 @@ nsInstallDlg::MajorProgressCB(char *aName, int aNum, int aTotal, int aActivity)
{
case ACT_DOWNLOAD:
if (!bDownload)
sprintf(msg, PREPARING, aName);
sprintf(msg, gCtx->Res("PREPARING"), aName);
break;
case ACT_EXTRACT:
sprintf(msg, EXTRACTING, aName);
sprintf(msg, gCtx->Res("EXTRACTING"), aName);
break;
case ACT_INSTALL:
sprintf(msg, INSTALLING_XPI, aName);
sprintf(msg, gCtx->Res("INSTALLING_XPI"), aName);
break;
default:
@ -460,7 +460,7 @@ nsInstallDlg::SetDownloadComp(char *aName, int aNum, int aTotal)
char label[64];
// major label format e.g., "Downloading Navigator [4/12] at 635 K/sec..."
sprintf(label, DOWNLOADING, aName, aNum, aTotal);
sprintf(label, gCtx->Res("DOWNLOADING"), aName, aNum, aTotal);
gtk_label_set_text(GTK_LABEL(sMajorLabel), label);
gettimeofday(&sDLStartTime, NULL);
@ -486,7 +486,7 @@ nsInstallDlg::DownloadCB(int aBytesRd, int aTotal)
percent = (gfloat)aBytesRd/(gfloat)aTotal;
// only update rate in major label line
sprintf(label, DLRATE, rate);
sprintf(label, gCtx->Res("DLRATE"), rate);
gtk_label_set_text(GTK_LABEL(sRateLabel), label);
gtk_progress_bar_update(GTK_PROGRESS_BAR(sMajorProgBar), percent);
@ -510,8 +510,8 @@ nsInstallDlg::ShowCompleteDlg()
// throw up completion notification
completeDlg = gtk_dialog_new();
label = gtk_label_new(COMPLETED);
okButton = gtk_button_new_with_label(OK_LABEL);
label = gtk_label_new(gCtx->Res("COMPLETED"));
okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL"));
packer = gtk_packer_new();
gtk_packer_set_default_border_width(GTK_PACKER(packer), 20);

Просмотреть файл

@ -148,7 +148,7 @@ nsLicenseDlg::Show(int aDirection)
licenseContents = GetLicenseContents();
if (!licenseContents)
{
err = E_EMPTY_LICENSE;
err = ErrorHandler(E_EMPTY_LICENSE);
goto BAIL;
}
@ -196,8 +196,8 @@ nsLicenseDlg::Show(int aDirection)
// always change the button titles to Accept/Decline
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->backLabel);
gCtx->acceptLabel = gtk_label_new(ACCEPT);
gCtx->declineLabel = gtk_label_new(DECLINE);
gCtx->acceptLabel = gtk_label_new(gCtx->Res("ACCEPT"));
gCtx->declineLabel = gtk_label_new(gCtx->Res("DECLINE"));
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel);
gtk_container_add(GTK_CONTAINER(gCtx->back), gCtx->declineLabel);
gtk_widget_show(gCtx->acceptLabel);

Просмотреть файл

@ -394,7 +394,7 @@ nsSetupTypeDlg::Show(int aDirection)
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
20, 20);
frame = gtk_frame_new(DEST_DIR);
frame = gtk_frame_new(gCtx->Res("DEST_DIR"));
gtk_table_attach_defaults(GTK_TABLE(destTable), frame, 0, 2, 0, 1);
gtk_widget_show(frame);
@ -408,7 +408,7 @@ nsSetupTypeDlg::Show(int aDirection)
gtk_widget_show(sFolder);
gtk_table_attach_defaults(GTK_TABLE(destTable), sFolder, 0, 1, 0, 1);
sBrowseBtn = gtk_button_new_with_label(BROWSE);
sBrowseBtn = gtk_button_new_with_label(gCtx->Res("BROWSE"));
gtk_widget_show(sBrowseBtn);
gtk_table_attach(GTK_TABLE(destTable), sBrowseBtn, 1, 2, 0, 1,
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
@ -436,8 +436,8 @@ nsSetupTypeDlg::Show(int aDirection)
// change the button titles back to Back/Next
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel);
gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->declineLabel);
gCtx->nextLabel = gtk_label_new(NEXT);
gCtx->backLabel = gtk_label_new(BACK);
gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
gCtx->backLabel = gtk_label_new(gCtx->Res("BACK"));
gtk_widget_show(gCtx->nextLabel);
gtk_widget_show(gCtx->backLabel);
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
@ -452,7 +452,7 @@ nsSetupTypeDlg::Show(int aDirection)
{
DUMP("Back from Install to Setup Type");
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->installLabel);
gCtx->nextLabel = gtk_label_new(NEXT);
gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
gtk_widget_show(gCtx->nextLabel);
gtk_widget_show(gCtx->next);
@ -615,7 +615,7 @@ nsSetupTypeDlg::SelectFolder(GtkWidget *aWidget, gpointer aData)
GtkWidget *fileSel = NULL;
char *selDir = gCtx->opt->mDestination;
fileSel = gtk_file_selection_new(SELECT_DIR);
fileSel = gtk_file_selection_new(gCtx->Res("SELECT_DIR"));
gtk_file_selection_set_filename(GTK_FILE_SELECTION(fileSel), selDir);
gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fileSel)->ok_button),
"clicked", (GtkSignalFunc) SelectFolderOK, fileSel);
@ -682,12 +682,12 @@ nsSetupTypeDlg::VerifyDestination()
return OK;
// destination doesn't exist so ask user if we should create it
sprintf(message, DOESNT_EXIST, gCtx->opt->mDestination);
sprintf(message, gCtx->Res("DOESNT_EXIST"), gCtx->opt->mDestination);
sCreateDestDlg = gtk_dialog_new();
label = gtk_label_new(message);
yesButton = gtk_button_new_with_label(YES_LABEL);
noButton = gtk_button_new_with_label(NO_LABEL);
yesButton = gtk_button_new_with_label(gCtx->Res("YES_LABEL"));
noButton = gtk_button_new_with_label(gCtx->Res("NO_LABEL"));
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sCreateDestDlg)->action_area),
yesButton);
@ -772,8 +772,8 @@ nsSetupTypeDlg::DeleteOldInst()
// throw up delete dialog
sDelInstDlg = gtk_dialog_new();
deleteBtn = gtk_button_new_with_label(DELETE_LABEL);
cancelBtn = gtk_button_new_with_label(CANCEL_LABEL);
deleteBtn = gtk_button_new_with_label(gCtx->Res("DELETE_LABEL"));
cancelBtn = gtk_button_new_with_label(gCtx->Res("CANCEL_LABEL"));
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(sDelInstDlg)->action_area),
deleteBtn);

Просмотреть файл

@ -133,7 +133,7 @@ nsWelcomeDlg::Show(int aDirection)
readmeContents = GetReadmeContents();
if (!readmeContents)
{
err = E_EMPTY_README;
err = ErrorHandler(E_EMPTY_README);
goto BAIL;
}
@ -181,8 +181,8 @@ nsWelcomeDlg::Show(int aDirection)
// change the button titles back to Back/Next
gtk_container_remove(GTK_CONTAINER(gCtx->next), gCtx->acceptLabel);
gtk_container_remove(GTK_CONTAINER(gCtx->back), gCtx->declineLabel);
gCtx->nextLabel = gtk_label_new(NEXT);
gCtx->backLabel = gtk_label_new(BACK);
gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
gCtx->backLabel = gtk_label_new(gCtx->Res("BACK"));
gtk_container_add(GTK_CONTAINER(gCtx->next), gCtx->nextLabel);
gtk_container_add(GTK_CONTAINER(gCtx->back), gCtx->backLabel);
gtk_widget_show(gCtx->nextLabel);

Просмотреть файл

@ -24,6 +24,8 @@
#include "nsXIContext.h"
#define __EOT__ "EndOfTable"
nsXIContext::nsXIContext()
{
me = NULL;
@ -53,12 +55,16 @@ nsXIContext::nsXIContext()
nextID = 0;
bMoving = FALSE;
bDone = FALSE;
reslist = NULL;
}
nsXIContext::~nsXIContext()
{
// NOTE: don't try to delete "me" cause I control thee
ReleaseResources();
XI_IF_DELETE(ldlg);
XI_IF_DELETE(wdlg);
XI_IF_DELETE(sdlg);
@ -109,3 +115,143 @@ nsXIContext::itoa(int n)
return s;
}
#define MAX_KEY_SIZE 64
#define FIRST_ERR -601
#define LAST_ERR -625
int
nsXIContext::LoadResources()
{
int err = OK;
nsINIParser *parser = new nsINIParser(RES_FILE);
kvpair *currkv = NULL;
char currkey[MAX_KEY_SIZE];
int len, i;
if (!parser)
return E_MEM;
char *strkeys[] =
{
"NEXT",
"BACK",
"CANCEL",
"ACCEPT",
"DECLINE",
"INSTALL",
"DEFAULT_TITLE",
"DEST_DIR",
"BROWSE",
"SELECT_DIR",
"DOESNT_EXIST",
"YES_LABEL",
"NO_LABEL",
"OK_LABEL",
"DELETE_LABEL",
"CANCEL_LABEL",
"ERROR",
"FATAL_ERROR",
"DESCRIPTION",
"DOWNLOADING",
"DLRATE",
"PREPARING",
"EXTRACTING",
"INSTALLING_XPI",
"PROCESSING_FILE",
"COMPLETED",
__EOT__
};
/* read in UI strings */
currkv = (kvpair *) malloc(sizeof(kvpair));
reslist = currkv;
for (i = 0; strcmp(strkeys[i], __EOT__) != 0; i++)
{
err = parser->GetStringAlloc(RES_SECT, strkeys[i],
&(currkv->val), &len);
if (err != OK)
goto BAIL;
currkv->key = strdup(strkeys[i]);
currkv->next = (kvpair *) malloc(sizeof(kvpair));
currkv = currkv->next;
if (i > 1024) /* inf loop prevention paranoia */
break;
}
currkv->next = NULL; /* seal off list */
/* read in err strings */
for (i = FIRST_ERR; i >= LAST_ERR; i--)
{
sprintf(currkey, "%d", i);
err = parser->GetStringAlloc(RES_SECT, currkey, &(currkv->val), &len);
if (err != OK)
goto BAIL;
currkv->key = strdup(currkey);
if (i == LAST_ERR)
break;
currkv->next = (kvpair *) malloc(sizeof(kvpair));
currkv = currkv->next;
}
currkv->next = NULL; /* seal off list */
BAIL:
if (err != OK)
{
fprintf(stderr, "FATAL ERROR: Failed to load resources!");
}
XI_IF_DELETE(parser);
return err;
}
int
nsXIContext::ReleaseResources()
{
int err = OK;
kvpair *currkv = NULL, *delkv = NULL;
/* empty list -- should never really happen */
if (!reslist)
return E_PARAM;
currkv = reslist;
while (currkv)
{
XI_IF_FREE(currkv->key);
XI_IF_FREE(currkv->val);
delkv = currkv;
currkv = currkv->next;
XI_IF_FREE(delkv);
}
return err;
}
char *
nsXIContext::Res(char *aKey)
{
char *val = NULL;
kvpair *currkv = NULL;
/* param check */
if (!aKey || !reslist)
return NULL;
/* search through linked list */
currkv = reslist;
while (currkv)
{
if (strcmp(aKey, currkv->key) == 0)
{
val = currkv->val;
break;
}
currkv = currkv->next;
}
return val;
}

Просмотреть файл

@ -31,9 +31,21 @@
#include "nsComponentsDlg.h"
#include "nsInstallDlg.h"
#include "nsXIOptions.h"
#include "nsINIParser.h"
#define RES_FILE "installer.prop"
#define RES_SECT "String Resources"
class nsXInstaller;
typedef struct _kvpair
{
char *key;
char *val;
struct _kvpair *next;
} kvpair;
class nsXIContext
{
public:
@ -81,6 +93,12 @@ public:
* Utilities
*-------------------------------------------------------------------*/
char *itoa(int n);
int LoadResources(); /* load string resources */
int ReleaseResources(); /* release alloc'd resource strings */
char *Res(char *aKey); /* get string resource for key; NULL==err */
private:
kvpair *reslist; /* string resource linked list */
};
#endif /* _NS_XICONTEXT_H_ */

Просмотреть файл

@ -46,6 +46,9 @@ nsXInstaller::ParseConfig()
nsINIParser *parser = NULL;
XI_ERR_BAIL(InitContext());
err = gCtx->LoadResources();
if (err != OK)
return err;
parser = new nsINIParser( CONFIG_INI );
if (!parser)
@ -126,7 +129,8 @@ nsXInstaller::RunWizard(int argc, char **argv)
if (mTitle)
gtk_window_set_title(GTK_WINDOW(gCtx->window), mTitle);
else
gtk_window_set_title(GTK_WINDOW(gCtx->window), DEFAULT_TITLE);
gtk_window_set_title(GTK_WINDOW(gCtx->window),
gCtx->Res("DEFAULT_TITLE"));
gtk_widget_show(gCtx->window);
// create and display the logo and cancel button
@ -209,7 +213,7 @@ nsXInstaller::DrawCancelButton(GtkWidget *aLogoVBox)
int err = OK;
GtkWidget *hbox;
gCtx->cancel = gtk_button_new_with_label(CANCEL);
gCtx->cancel = gtk_button_new_with_label(gCtx->Res("CANCEL"));
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), gCtx->cancel, TRUE, TRUE, 15);
gtk_box_pack_end(GTK_BOX(aLogoVBox), hbox, FALSE, TRUE, 10);
@ -234,8 +238,8 @@ nsXInstaller::DrawNavButtons()
gCtx->next = gtk_button_new();
gCtx->back = gtk_button_new();
gCtx->nextLabel = gtk_label_new(NEXT);
gCtx->backLabel = gtk_label_new(BACK);
gCtx->nextLabel = gtk_label_new(gCtx->Res("NEXT"));
gCtx->backLabel = gtk_label_new(gCtx->Res("BACK"));
XI_VERIFY(gCtx->next);
XI_VERIFY(gCtx->back);
gtk_widget_show(gCtx->next);
@ -326,3 +330,64 @@ main(int argc, char **argv)
_exit(err);
}
/*------------------------------------------------------------------*
* Default Error Handler
*------------------------------------------------------------------*/
int
ErrorHandler(int aErr)
{
GtkWidget *okButton, *label, *dialog;
char msg[256];
char errStr[16];
sprintf(errStr, "%d", aErr);
if (!IsErrFatal(aErr))
sprintf(msg, gCtx->Res("ERROR"), aErr, gCtx->Res(errStr));
else
sprintf(msg, gCtx->Res("FATAL_ERROR"), aErr, gCtx->Res(errStr));
dialog = gtk_dialog_new();
okButton = gtk_button_new_with_label(gCtx->Res("OK_LABEL"));
label = gtk_label_new(msg);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
okButton);
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
GTK_SIGNAL_FUNC(ErrDlgOK), (void*)aErr);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
gtk_widget_show_all(dialog);
return aErr;
}
void
ErrDlgOK(GtkWidget *aWidget, gpointer aData)
{
int err = (int) aData;
gtk_widget_destroy(aWidget);
if (IsErrFatal(err))
exit(err);
}
int
IsErrFatal(int aErr)
{
int bFatal = TRUE;
/* non-fatal errors */
switch (aErr)
{
case -620:
case -621:
case -624:
case -625:
bFatal = FALSE;
default:
break;
}
return bFatal;
}

Просмотреть файл

@ -56,7 +56,9 @@ private:
};
int main(int argc, char **argv);
int ErrorHandler(int aErr);
void ErrDlgOK(GtkWidget *aWidget, gpointer aData);
int IsErrFatal(int aErr);
#define CONFIG_INI "config.ini"