~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to kmail/kmkernel.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "mailcommon/pop3settings.h"
24
24
#include "mailcommon/foldertreeview.h"
25
25
#include "mailcommon/filter/kmfilterdialog.h"
26
 
 
 
26
#include "pimcommon/pimutil.h"
27
27
 
28
28
// kdepim includes
29
29
#include "kdepim-version.h"
50
50
#include "messagecomposersettings.h"
51
51
#include "messagecomposer/messagehelper.h"
52
52
#include "messagecomposer/messagecomposersettings.h"
 
53
#include "messagecomposer/autocorrection/composerautocorrection.h"
53
54
 
54
55
#include "templateparser/templateparser.h"
55
56
#include "templateparser/globalsettings_base.h"
120
121
KMKernel::KMKernel (QObject *parent, const char *name) :
121
122
  QObject(parent),
122
123
  mIdentityManager(0), mConfigureDialog(0), mMailService(0),
123
 
  mSystemNetworkStatus ( Solid::Networking::status() )
 
124
  mSystemNetworkStatus ( Solid::Networking::status() ), mSystemTray(0)
124
125
{
125
126
  Akonadi::AttributeFactory::registerAttribute<Akonadi::SearchDescriptionAttribute>();
126
127
  QDBusConnection::sessionBus().registerService("org.kde.kmail");
148
149
  mJobScheduler = new JobScheduler( this );
149
150
  mXmlGuiInstance = KComponentData();
150
151
 
 
152
  mAutoCorrection = new MessageComposer::ComposerAutoCorrection();
151
153
  KMime::setFallbackCharEncoding( MessageCore::GlobalSettings::self()->fallbackCharacterEncoding() );
152
154
  KMime::setUseOutlookAttachmentEncoding( MessageComposer::MessageComposerSettings::self()->outlookCompatibleAttachments() );
153
155
 
215
217
 
216
218
  connect ( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)),
217
219
            this, SLOT(slotSystemNetworkStatusChanged(Solid::Networking::Status)) );
218
 
  
 
220
 
219
221
  connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*)),
220
222
           this, SLOT(slotProgressItemCompletedOrCanceled(KPIM::ProgressItem*)) );
221
223
  connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
231
233
  delete mMailService;
232
234
  mMailService = 0;
233
235
 
 
236
  mSystemTray = 0;
 
237
 
234
238
  stopAgentInstance();
235
239
  slotSyncConfig();
236
240
 
 
241
  delete mAutoCorrection;
237
242
  mySelf = 0;
238
243
  kDebug();
239
244
}
849
854
 
850
855
  TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage );
851
856
  parser.setIdentityManager( identityManager() );
852
 
  parser.process( msg, folder ? folder->collection() : Akonadi::Collection() );
 
857
  Akonadi::Collection col = folder ? folder->collection() : Akonadi::Collection();
 
858
  parser.process( msg, col );
853
859
 
854
860
  KMail::Composer *win = makeComposer( msg, false, false, KMail::Composer::New, id );
855
861
 
 
862
  win->setCollectionForNewMessage(col);
856
863
  //Add the attachment if we have one
857
864
  if ( !attachURL.isEmpty() && attachURL.isValid() ) {
858
865
    win->addAttachment( attachURL, "" );
936
943
    return;
937
944
 
938
945
  setAccountStatus(false);
939
 
  
 
946
 
940
947
  GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Offline );
941
948
  BroadcastStatus::instance()->setStatusMsg( i18n("KMail is set to be offline; all network jobs are suspended"));
942
949
  emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
947
954
{
948
955
  const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(false);
949
956
  foreach ( Akonadi::AgentInstance type, lst ) {
950
 
    const QString identifier( type.identifier() ); 
 
957
    const QString identifier( type.identifier() );
951
958
    if ( identifier.contains( IMAP_RESOURCE_IDENTIFIER ) ||
952
959
         identifier.contains( POP3_RESOURCE_IDENTIFIER ) ||
953
960
         identifier.contains( MAILDISPATCHER_RESOURCE_IDENTIFIER ) ) {
977
984
  }
978
985
  GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Online );
979
986
  emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
 
987
  KMMainWidget *widget = getKMMainWidget();
 
988
  if ( widget  ) {
 
989
    widget->clearViewer();
 
990
  }
980
991
}
981
992
 
982
993
bool KMKernel::isOffline()
1431
1442
 
1432
1443
bool KMKernel::haveSystemTrayApplet() const
1433
1444
{
1434
 
  return !systemTrayApplets.isEmpty();
 
1445
  return (mSystemTray!=0);
1435
1446
}
1436
1447
 
1437
1448
void KMKernel::updateSystemTray()
1438
1449
{
1439
 
  if ( haveSystemTrayApplet() ) {
1440
 
    const int nbSystemTray = systemTrayApplets.count();
1441
 
    for (int i = 0; i < nbSystemTray; ++i) {
1442
 
      systemTrayApplets.at( i )->updateSystemTray();
1443
 
    }
1444
 
  }
1445
 
}
1446
 
 
1447
 
bool KMKernel::registerSystemTrayApplet( KMail::KMSystemTray* applet )
1448
 
{
1449
 
  if ( !systemTrayApplets.contains( applet ) ) {
1450
 
    systemTrayApplets.append( applet );
1451
 
    return true;
1452
 
  }
1453
 
  else
1454
 
    return false;
1455
 
}
1456
 
 
1457
 
bool KMKernel::unregisterSystemTrayApplet( KMail::KMSystemTray* applet )
1458
 
{
1459
 
  return systemTrayApplets.removeAll( applet ) > 0;
1460
 
}
1461
 
 
 
1450
  if ( mSystemTray ) {
 
1451
    mSystemTray->updateSystemTray();
 
1452
  }
 
1453
}
1462
1454
 
1463
1455
KPIMIdentities::IdentityManager * KMKernel::identityManager() {
1464
1456
  if ( !mIdentityManager ) {
1618
1610
  if ( KMMainWidget::mainWidgetList() &&
1619
1611
       KMMainWidget::mainWidgetList()->count() > 1 )
1620
1612
    return true;
1621
 
  KMMainWidget *widget = getKMMainWidget();
1622
 
  if ( !widget )
1623
 
    return true;
1624
 
  KMail::KMSystemTray* systray = widget->systray();
1625
 
  if ( !systray || GlobalSettings::closeDespiteSystemTray() )
 
1613
  if ( !mSystemTray || GlobalSettings::closeDespiteSystemTray() )
1626
1614
      return true;
1627
 
  if ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) {
1628
 
    systray->hideKMail();
 
1615
  if ( mSystemTray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) {
 
1616
    mSystemTray->hideKMail();
1629
1617
    return false;
1630
 
  } else if ( ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) && ( systray->hasUnreadMail() )) {
1631
 
    systray->setStatus( KStatusNotifierItem::Active );
1632
 
    systray->hideKMail();
 
1618
  } else if ( ( mSystemTray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) && ( mSystemTray->hasUnreadMail() )) {
 
1619
    mSystemTray->setStatus( KStatusNotifierItem::Active );
 
1620
    mSystemTray->hideKMail();
1633
1621
    return false;
1634
1622
  }
1635
1623
  return true;
1718
1706
 
1719
1707
void KMKernel::instanceStatusChanged( Akonadi::AgentInstance instance )
1720
1708
{
 
1709
  if (instance.identifier() == QLatin1String( "akonadi_mailfilter_agent" ) ) {
 
1710
     // Creating a progress item twice is ok, it will simply return the already existing
 
1711
      // item
 
1712
      KPIM::ProgressItem *progress =  KPIM::ProgressManager::createProgressItem( 0, instance,
 
1713
                                        instance.identifier(), instance.name(), instance.statusMessage(),
 
1714
                                        false, true );
 
1715
      progress->setProperty( "AgentIdentifier", instance.identifier() );
 
1716
      return;
 
1717
  }
1721
1718
  if ( MailCommon::Util::agentInstances(true).contains( instance ) ) {
1722
1719
    if ( instance.status() == Akonadi::AgentInstance::Running ) {
1723
1720
 
1736
1733
          useCrypto = mResourceCryptoSettingCache.value(identifier);
1737
1734
      } else {
1738
1735
        if ( identifier.contains( IMAP_RESOURCE_IDENTIFIER ) ) {
1739
 
            OrgKdeAkonadiImapSettingsInterface *iface = MailCommon::Util::createImapSettingsInterface( identifier );
 
1736
            OrgKdeAkonadiImapSettingsInterface *iface = PimCommon::Util::createImapSettingsInterface( identifier );
1740
1737
            if ( iface->isValid() ) {
1741
1738
                const QString imapSafety = iface->safety();
1742
1739
                useCrypto = ( imapSafety == QLatin1String( "SSL" ) || imapSafety == QLatin1String( "STARTTLS" ) );
1753
1750
        }
1754
1751
     }
1755
1752
 
1756
 
      
 
1753
 
1757
1754
      // Creating a progress item twice is ok, it will simply return the already existing
1758
1755
      // item
1759
1756
      KPIM::ProgressItem *progress =  KPIM::ProgressManager::createProgressItem( 0, instance,
1903
1900
    if ( type.status() == Akonadi::AgentInstance::Broken )
1904
1901
      continue;
1905
1902
    if ( type.identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
1906
 
      OrgKdeAkonadiImapSettingsInterface *iface = MailCommon::Util::createImapSettingsInterface( type.identifier() );
 
1903
      OrgKdeAkonadiImapSettingsInterface *iface = PimCommon::Util::createImapSettingsInterface( type.identifier() );
1907
1904
      if ( iface->isValid() ) {
1908
1905
        foreach( const Akonadi::Collection& collection, collectionList ) {
1909
1906
          const Akonadi::Collection::Id collectionId = collection.id();
1911
1908
            //Use default trash
1912
1909
            iface->setTrashCollection( CommonKernel->trashCollectionFolder().id() );
1913
1910
            iface->writeConfig();
1914
 
            break; 
 
1911
            break;
1915
1912
          }
1916
1913
        }
1917
1914
      }
2012
2009
  }
2013
2010
}
2014
2011
 
 
2012
void KMKernel::resourceGoOnLine()
 
2013
{
 
2014
  KMMainWidget *widget = getKMMainWidget();
 
2015
  if ( widget  ) {
 
2016
    if(widget->currentFolder()) {
 
2017
      Akonadi::Collection collection = widget->currentFolder()->collection();
 
2018
      Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance( collection.resource() );
 
2019
      instance.setIsOnline( true );
 
2020
      widget->clearViewer();
 
2021
    }
 
2022
  }
 
2023
}
 
2024
 
 
2025
void KMKernel::makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode mode)
 
2026
{
 
2027
  switch(mode) {
 
2028
  case MessageViewer::Viewer::AllResources:
 
2029
    resumeNetworkJobs();
 
2030
    break;
 
2031
  case MessageViewer::Viewer::SelectedResource:
 
2032
    resourceGoOnLine();
 
2033
    break;
 
2034
  }
 
2035
}
 
2036
 
 
2037
MessageComposer::ComposerAutoCorrection* KMKernel::composerAutoCorrection()
 
2038
{
 
2039
  return mAutoCorrection;
 
2040
}
 
2041
 
 
2042
void KMKernel::toggleSystemTray()
 
2043
{
 
2044
  KMMainWidget *widget = getKMMainWidget();
 
2045
  if ( widget  ) {
 
2046
    if ( !mSystemTray && GlobalSettings::self()->systemTrayEnabled() ) {
 
2047
      mSystemTray = new KMail::KMSystemTray(widget);
 
2048
    } else if ( mSystemTray && !GlobalSettings::self()->systemTrayEnabled() ) {
 
2049
      // Get rid of system tray on user's request
 
2050
      kDebug() << "deleting systray";
 
2051
      delete mSystemTray;
 
2052
      mSystemTray = 0;
 
2053
    }
 
2054
 
 
2055
    // Set mode of systemtray. If mode has changed, tray will handle this.
 
2056
    if ( mSystemTray ) {
 
2057
      mSystemTray->setMode( GlobalSettings::self()->systemTrayPolicy() );
 
2058
      mSystemTray->setShowUnread( GlobalSettings::self()->systemTrayShowUnread() );
 
2059
    }
 
2060
 
 
2061
  }
 
2062
}
 
2063
 
 
2064
 
2015
2065
#include "kmkernel.moc"