/* Aileron.h: misc. functions and a structure of global items.
 *
 * This file is part of Aileron, a WINGs email client. 
 *
 *  Copyright (c) 1999-2000 Nwanua Elumeze
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _AILERON_GLOBAL_
#define _AILERON_GLOBAL_


#define VERSION "0.1.3"

#define SIMPLEBELL 1
#define DEBUG      1


#include <WINGs/WINGs.h>
#include <WMaker.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <locale.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include <assert.h>

#include <X11/keysym.h>
#include <X11/xpm.h>
#include <X11/Xresource.h>

/* University of Washington's c-client (mail) library */
#include <mail.h>
#include <osdep.h>
#include <rfc822.h>
#include <smtp.h>
#include <misc.h>


struct {
  Display        *display;
  WMScreen       *screen;
  Window         leader;
  WMAppContext   *appContext;
  
  WMUserDefaults *defaultsDB;
  WMBag          *openMboxes, *openComposers;
  WMHashTable    *windowTable;
  XContext       xContext;
  char           *tmpdir, *errorMsg;


  WMMenu         *menu;

  GC             blackgc, whitegc, greygc, darkgreygc;

  WMColor        *whiteColor;
  WMFont         *listfont, *buttonfont, *copiedfont;
  WMPixmap       *npix_w, *npix_g, *mpix_w, *mpix_g, *apix_w, *apix_g;

  WMPixmap       *SoundIcon, *ApplicationIcon, *ImageIcon;
  WMPixmap       *MovieIcon, *UnknownIcon, *ComposerImage;

  MAILSTREAM      *selectedStream;
  unsigned long   selectedMessage;
  char            *selectionText;
  WMRulerMargins  *rulermargins;
    
  void            *mbox, *composer;
  unsigned short  cORm:1; /* composer=0; mbox = 1 */
  unsigned short  mboxesCreated:1;
  unsigned short  addressesCreated:1;
  unsigned short  findCreated:1;
  unsigned short  infoCreated:1;
  unsigned short  gplCreated:1;
  unsigned short  helpCreated:1;
  unsigned short  aileronQuitting:1;
  unsigned short  mboxLocked:1;
  unsigned short  shiftHeld:1;
  unsigned short  prefsChanged:1;
  unsigned short  mouseWithinSumary:1;
  unsigned short  ignoreError:1;
  unsigned short  textIsPlain:1;
  unsigned short  RESERVED:2;

} Aileron;



WMButton* CreateBlendedButton(WMWidget *parent, WMButtonType type,
  const char *text, const char *imagefile);

int RunAlertPanel(char *title, char *msg,
  char *defaultButton, char *alternateButton, char *otherButton);

Bool FileExists(char *filename);
void FSErrorhandler(char *title, char *path, int errornumber);


void RunMailboxesPanel(void);
void ResetMailboxesPanel(void);

void RunPrefsPanel(void);
void SaveGeometriesFor(char *what, WMSize size, 
  WMPoint pos, int misc);
Bool GetGeometriesFor(char *what, WMSize *size, 
  WMPoint *pos, int *misc);
  



char *RunPasswordPanel(WMScreen *scrPtr, WMWindow *owner, char *title,
  char *msg, char *defaultText, char *okButton, char *cancelButton,
  char *name);

void OpenFile(WMTextDelegate *self, char *description);

void QuitAileron(void);

void RunFindPanel(void);
void FindPrevious(void);
void FindNext(void);
void ChangeFindPanelForContext(void);

void RunInfoPanel(void);
void RunGPLPanel(void);
void RunHelpPanel(int page);
void CloseHelpPanel(void);

void HTMLParser(WMWidget *w, void *vstream);
void HTMLWriter(WMWidget *w, void *vstream);


void RunAddressesPanel(void);
void SaveAddresses(void);
char *ExpandAddress(char *name);
void AddAddress(void *vmbox);
char * GetCharFromAddress(ADDRESS *addr);

void ComposeMessage(int type);
void ComposeMessageTo(char *to);
void CloseComposer(void *vc);
void AddAttachment(void *vc);
void DeliverMessage(void *vc);
void PostComposeError(int type);
void AppendCC(void *vc, char *text);
void AppendTo(void *vc, char *text);
void ShowSendOptionsPanel(void *vc);
void SaveDraft(void *vc);
void RestoreDraft(void);
WMWindow *GetComposerWindow(void *vc);
WMText *GetComposerMessageView(void *vc);
void SetComposerTextAlignment(void *vc, WMAlignment alignment);
void HideShowComposerRuler(void *vc);



void OpenMailBox(const char *name);
void CloseMailBox(char *name);
Bool OpenDefaultMailBoxes(void);
void ShowMessageSizes(void);
void ShowDeletedMessages(void);
void RunMailBoxAlertPanel(char *name);
void SaveAllAttachments(void *vmbox);
void RestoreMailBoxWindowTitle(void *vmbox);
void SetMailBoxWindowTitle(void *vmbox, char *title);
void MarkMailBoxAsReadOnly(void *vmbox, Bool rdonly);
void FocusMailBox(void *vmbox, Bool focus);
void SortMailSummaries(void *vmbox, int type, int reverse);
void CompactMailBox(void *vmbox);
void RefreshMailBoxes(void);
void RefreshMailBoxSummary(void *vmbox);
char *GetMailBoxName(void *vmbox);
void *GetMailBoxForName(char *name);
MAILSTREAM *GetMailBoxStream(void *vmbox);
WMWindow *GetMailBoxWindow(void *vmbox);
WMText *GetMailBoxMessageView(void *vc);
WMList *GetMailBoxSummaryView(void *vmbox);
int GetMailBoxSortType(void *vmbox);
int GetMailBoxReverseSort(void *vmbox);
Bool MailBoxIsIMAP(void *vmbox);
Bool MailBoxIsPOP(void *vmbox);
Bool MailBoxIsNetwork(void *vmbox);


void NextMessage(void *vmbox, int direction);
void MarkMessagesAsRead(void *vmbox, Bool read);
Bool MarkMessagesAsDeleted(void *vmbox, Bool del);
void MarkMessagesAsAnswered(void *vmbox, Bool answered);
Bool GetMessage(void *vmbox, unsigned long msgno, int alternative);
unsigned long GetMailBoxTotalMessages(void *vmbox);
unsigned long GetMailBoxSelectedMessage(void *vmbox);
WMArray *GetMailBoxSelectedMessages(void *vmbox);
void SelectMailBoxMessage(void *vmbox, int message);
Bool MarkMessageAsDeleted(void *vmbox, Bool del);


void FetchMessagePart(WMText *tPtr, MAILSTREAM *stream, 
  unsigned long msgno, BODY *body, char *pfx, 
  unsigned long section, short alternative, short prefix);



void BuildMainMenu(void);

void *CreateTimeStamp(WMWidget *parent);
void SetTimeStampWithTimeT(void *vtimestamp, time_t time);
void SetTimeStampWithTimeTM(void *vtimestamp, struct tm *time);


WMLabel *NewLabel(WMWidget *w, char *name,
  int pos_x, int pos_y, int size_x, int size_y);

WMTextField *NewTextField(WMWidget *w, char *text,
  int pos_x, int pos_y, int size_x, int size_y);

char *SetEntity(WMWindow *owner, char *entity, 
  int isDir, char *warning, int setDefault);

void EnterSelection(void);


enum{CMCompose=0, CMReply, CMReplyAll, CMForward, CMBounce};
enum{next_SAME=0, next_UP, next_DOWN, page_UP, page_DOWN};
enum{byDate=0, byArrival, bySender, bySize, bySubject};
enum{bestAlternative=0, firstAlternative, allAlternatives};


#endif
