summaryrefslogtreecommitdiffstats
path: root/svx/source/dialog/sendreportunx.cxx
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2004-11-26 13:21:30 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2004-11-26 13:21:30 +0000
commit1c7956ab9afc3f46ab528bc805fb1fe02391d923 (patch)
tree0f68540692b47b7bb080ab0eec6ac79be4d42fd0 /svx/source/dialog/sendreportunx.cxx
parentINTEGRATION: CWS recovery04 (1.1.2); FILE ADDED (diff)
downloadcore-1c7956ab9afc3f46ab528bc805fb1fe02391d923.tar.gz
core-1c7956ab9afc3f46ab528bc805fb1fe02391d923.zip
INTEGRATION: CWS recovery04 (1.1.2); FILE ADDED
2004/11/01 12:18:20 hro 1.1.2.3: #i34683# Commited missing changes 2004/10/12 08:17:31 hro 1.1.2.2: #i33881# Send reports only after UI has completed 2004/09/03 04:54:27 hro 1.1.2.1: #i28480# Sending only mode for crash reporter
Diffstat (limited to 'svx/source/dialog/sendreportunx.cxx')
-rw-r--r--svx/source/dialog/sendreportunx.cxx219
1 files changed, 219 insertions, 0 deletions
diff --git a/svx/source/dialog/sendreportunx.cxx b/svx/source/dialog/sendreportunx.cxx
new file mode 100644
index 000000000000..5f392af8a705
--- /dev/null
+++ b/svx/source/dialog/sendreportunx.cxx
@@ -0,0 +1,219 @@
+#include "docrecovery.hxx"
+#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#define RCFILE ".crash_reportrc"
+
+using namespace ::std;
+
+static const char *get_home_dir()
+{
+ struct passwd *ppwd = getpwuid( getuid() );
+
+ return ppwd ? (ppwd->pw_dir ? ppwd->pw_dir : "/") : "/";
+}
+
+static bool read_line( FILE *fp, string& rLine )
+{
+ char szBuffer[1024];
+ bool bSuccess = false;
+ bool bEOL = false;
+ string line;
+
+
+ while ( !bEOL && fgets( szBuffer, sizeof(szBuffer), fp ) )
+ {
+ int len = strlen(szBuffer);
+
+ bSuccess = true;
+
+ while ( len && szBuffer[len - 1] == '\n' )
+ {
+ szBuffer[--len] = 0;
+ bEOL = true;
+ }
+
+ line.append( szBuffer );
+ }
+
+ rLine = line;
+ return bSuccess;
+}
+
+static string trim_string( const string& rString )
+{
+ string temp = rString;
+
+ while ( temp.length() && temp[0] == ' ' || temp[0] == '\t' )
+ temp.erase( 0, 1 );
+
+ string::size_type len = temp.length();
+
+ while ( len && temp[len-1] == ' ' || temp[len-1] == '\t' )
+ {
+ temp.erase( len - 1, 1 );
+ len = temp.length();
+ }
+
+ return temp;
+}
+
+static string get_profile_string( const char *pFileName, const char *pSectionName, const char *pKeyName, const char *pDefault = NULL )
+{
+ FILE *fp = fopen( pFileName, "r" );
+ string retValue = pDefault ? pDefault : "";
+
+ if ( fp )
+ {
+ string line;
+ string section;
+
+ while ( read_line( fp, line ) )
+ {
+ line = trim_string( line );
+
+ if ( line.length() && line[0] == '[' )
+ {
+ line.erase( 0, 1 );
+ string::size_type end = line.find( ']', 0 );
+
+ if ( string::npos != end )
+ section = trim_string( line.substr( 0, end ) );
+ }
+ else
+ {
+
+ string::size_type iEqualSign = line.find( '=', 0 );
+
+ if ( iEqualSign != string::npos )
+ {
+ string keyname = line.substr( 0, iEqualSign );
+ keyname = trim_string( keyname );
+
+ string value = line.substr( iEqualSign + 1, -1 );
+ value = trim_string( value );
+
+ if (
+ 0 == strcasecmp( section.c_str(), pSectionName ) &&
+ 0 == strcasecmp( keyname.c_str(), pKeyName )
+ )
+ {
+ retValue = value;
+ break;
+ }
+ }
+ }
+ }
+
+ fclose( fp );
+ }
+
+ return retValue;
+}
+
+static bool get_profile_bool( const char *pFileName, const char *pSectionName, const char *pKeyName )
+{
+ string str = get_profile_string( pFileName, pSectionName, pKeyName );
+
+ if ( !strcasecmp( str.c_str(), "true" ) )
+ return true;
+ return false;
+}
+
+static String get_profile_String( const char *pFileName, const char *pSectionName, const char *pKeyName, const char *pDefault = NULL )
+{
+ string str = get_profile_string( pFileName, pSectionName, pKeyName );
+ String result( str.c_str(), RTL_TEXTENCODING_UTF8 );
+
+ return result;
+}
+
+namespace svx{
+ namespace DocRecovery{
+
+ bool ErrorRepSendDialog::ReadParams()
+ {
+ string sRCFile = get_home_dir();
+
+ sRCFile += "/";
+ sRCFile += string(RCFILE);
+
+ maEMailAddrED.SetText( get_profile_String( sRCFile.c_str(), "Options", "ReturnAddress" ) );
+ maParams.maHTTPProxyServer = get_profile_String( sRCFile.c_str(), "Options", "ProxyServer" );
+ maParams.maHTTPProxyPort = get_profile_String( sRCFile.c_str(), "Options", "ProxyPort" );
+ maParams.miHTTPConnectionType = get_profile_bool( sRCFile.c_str(), "Options", "UseProxy" ) ? 2 : 1;
+ maContactCB.Check( get_profile_bool( sRCFile.c_str(), "Options", "AllowContact" ) );
+
+ return true;
+ }
+
+ bool ErrorRepSendDialog::SaveParams()
+ {
+ bool success = false;
+ string sRCFile = get_home_dir();
+
+ sRCFile += "/";
+ sRCFile += string(RCFILE);
+
+ FILE *fp = fopen( sRCFile.c_str(), "w" );
+
+ if ( fp )
+ {
+ fprintf( fp, "[Options]\n" );
+ fprintf( fp, "UseProxy=%s\n", 2 == maParams.miHTTPConnectionType ? "true" : "false" );
+ fprintf( fp, "ProxyServer=%s\n", ByteString( maParams.maHTTPProxyServer, RTL_TEXTENCODING_UTF8 ).GetBuffer() );
+ fprintf( fp, "ProxyPort=%s\n", ByteString( maParams.maHTTPProxyPort, RTL_TEXTENCODING_UTF8 ).GetBuffer() );
+ fprintf( fp, "ReturnAddress=%s\n", ByteString( GetEMailAddress(), RTL_TEXTENCODING_UTF8 ).GetBuffer() );
+ fprintf( fp, "AllowContact=%s\n", IsContactAllowed() ? "true" : "false" );
+ fclose( fp );
+ }
+
+ return success;
+ }
+
+ bool ErrorRepSendDialog::SendReport()
+ {
+ ByteString strSubject( GetDocType(), RTL_TEXTENCODING_UTF8 );
+
+#ifdef LINUX
+ setenv( "ERRORREPORT_SUBJECT", strSubject.GetBuffer(), 1 );
+#else
+ static ::rtl::OString strEnvSubject = "ERRORREPORT_SUBJECT";
+ strEnvSubject += "=";
+ strEnvSubject += strSubject.GetBuffer();
+ putenv( (char *)strEnvSubject.getStr() );
+#endif
+
+ char szBodyFile[L_tmpnam] = "";
+ FILE *fp = fopen( tmpnam( szBodyFile ), "w" );
+
+ if ( fp )
+ {
+ ByteString strUTF8( GetUsing(), RTL_TEXTENCODING_UTF8 );
+
+ fwrite( strUTF8.GetBuffer(), 1, strUTF8.Len(), fp );
+ fclose( fp );
+#ifdef LINUX
+ setenv( "ERRORREPORT_BODYFILE", szBodyFile, 1 );
+#else
+ static ::rtl::OString strEnvBodyFile = "ERRORREPORT_BODYFILE";
+ strEnvBodyFile += "=";
+ strEnvBodyFile += szBodyFile;
+ putenv( (char *)strEnvBodyFile.getStr() );
+#endif
+ }
+
+ int ret = system( "crash_report -load -send -noui" );
+
+ if ( szBodyFile[0] );
+ unlink( szBodyFile );
+
+ return -1 != ret;
+ }
+
+
+ } // namespace DocRecovery
+} // namespace svx