Ejemplo n.º 1
0
        public SettingsWindow()
        {
            InitializeComponent();

            this.apiWrapper = MastodonAPIWrapper.sharedApiWrapper;

            int topMargin = 43;

            accountUIHandlers = new List <AccountUIHandler>();

            foreach (Account twitterAccount in MastodonAPIWrapper.sharedApiWrapper.accounts)
            {
                AccountUIHandler accountUIHandler = new AccountUIHandler();
                accountUIHandler.twitterAccountToken = twitterAccount.accessToken;

                Button accountButton = new Button();
                accountButton.ClipToBounds        = false;
                accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                accountButton.VerticalAlignment   = VerticalAlignment.Top;
                accountButton.Height = 50;
                accountButton.Margin = new Thickness(13, topMargin, 0, 0);
                accountButton.Style  = Resources["FlatButton"] as Style;
                accountButton.Click += Account_Click;
                accountButton.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(accountButton);
                accountUIHandler.accountButton = accountButton;
                topMargin += 60;

                Image accountImage = new Image();
                accountImage.Clip             = new RectangleGeometry(new Rect(0, 0, 50, 50), 4, 4);
                accountButton.Content         = accountImage;
                accountUIHandler.accountImage = accountImage;

                accountImage.Opacity = 0;
                this.apiWrapper.getProfileAvatar(twitterAccount, accountImage);

                accountUIHandlers.Add(accountUIHandler);
            }

            Button homeBtn = new Button();

            homeBtn.HorizontalAlignment = HorizontalAlignment.Left;
            homeBtn.VerticalAlignment   = VerticalAlignment.Top;
            homeBtn.Style  = Resources["FlatTab"] as Style;
            homeBtn.Height = 40;
            homeBtn.Margin = new Thickness(4, topMargin, 0, 0);
            homeBtn.Cursor = Cursors.Hand;
            this.sidebarGrid.Children.Add(homeBtn);

            TabImage tabImage = new TabImage();

            tabImage.Height              = 30;
            tabImage.Width               = 38;
            tabImage.Source              = new BitmapImage(new Uri("Resources/add.png", UriKind.Relative));
            tabImage.VerticalAlignment   = VerticalAlignment.Center;
            tabImage.HorizontalAlignment = HorizontalAlignment.Center;
            tabImage.Margin              = new Thickness(2, 1, 20, 1);
            homeBtn.Content              = tabImage;
        }
Ejemplo n.º 2
0
        public MastodonAPIWrapper()
        {
            Console.WriteLine("Initializing Capella Mastodon API Wrapper...");

            sharedApiWrapper = this;
            sharedOAuthUtils = new OAuthUtils();

            try
            {
                if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Capella\\settings.json"))
                {
                    return;
                }
                String  rawJson = File.ReadAllText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Capella\\settings.json");
                dynamic json    = JsonConvert.DeserializeObject(rawJson);

                if (json["version"] != null)
                {
                    double version = json["version"];
                    if (version < 0.3)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }

                if (json["nightModeEnabled"] != null)
                {
                    nightModeEnabled = (bool)json["nightModeEnabled"];
                }

                if (json["mutes"] != null)
                {
                    dynamic mutes = json["mutes"];
                    if (mutes["keywords"] != null)
                    {
                        JArray rawKeywords = mutes["keywords"];
                        foreach (String keyword in rawKeywords.Children())
                        {
                            keywords.Add(keyword);
                        }
                    }
                }

                dynamic accountsTokens = json["accounts"];
                if (accountsTokens == null)
                {
                    return;
                }

                if (accountsTokens.Count == 0)
                {
                    return;
                }

                Console.WriteLine("Loading Accounts...");

                accounts = new List <Account>();
                foreach (dynamic accountTokens in accountsTokens)
                {
                    Account account = new Account();
                    account.accessToken = (String)accountTokens["token"];

                    account.endpoint = (String)accountTokens["endpoint"];

                    account.myHandle = getCurrentHandle(account);

                    account.blockedIDs = new List <String>();

                    /*BackgroundWorker worker = new BackgroundWorker();
                     * worker.DoWork += (sender, e) =>
                     *  {
                     *      JObject rawData = (JObject)JsonConvert.DeserializeObject(sharedOAuthUtils.GetData("https://localhost/1.1/blocks/ids.json", "stringify_ids=true", account, true));
                     *      JArray blockedIDs = (JArray)rawData["ids"];
                     *      foreach (JValue id in blockedIDs.Children())
                     *      {
                     *          account.blockedIDs.Add((String)id);
                     *      }
                     *  };
                     * worker.RunWorkerAsync();*/

                    accounts.Add(account);
                }

                accountImages = new Dictionary <string, Image>();

                selectedAccount = accounts[0];
                String[] args = Environment.GetCommandLineArgs();
                if (args.Length > 1)
                {
                    String rawSelectedAccount = args[1];
                    int    selectedIdx;
                    if (Int32.TryParse(rawSelectedAccount, out selectedIdx))
                    {
                        if (selectedIdx < accounts.Count)
                        {
                            selectedAccount = accounts[selectedIdx];
                        }
                    }
                }
                Console.WriteLine("Capella Mastodon API Wrapper Initialized.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();

            if (Environment.OSVersion.Version.Minor == 0 || Environment.OSVersion.Version.Minor == 1) //Vista and Win7
            {
                //roundCornersHandler.RadiusX = 10;
                //roundCornersHandler.RadiusY = 10;
                mainGrid.Background = new SolidColorBrush(Color.FromArgb(64, 0, 0, 0));
            }

            this.apiWrapper = MastodonAPIWrapper.sharedApiWrapper;

            new NotificationsHandler();
            sharedMainWindow = this;

            closeBtn_MouseDown(null, null);
            minimizeBtn_MouseDown(null, null);

            this.Show();

            tabController                     = new TabsController();
            tabController.parentGrid          = this.mainGrid;
            tabController.parentWindow        = this;
            tabController.ClipToBounds        = true;
            tabController.Margin              = new Thickness(77, 1, 1, 1);
            tabController.VerticalAlignment   = VerticalAlignment.Stretch;
            tabController.HorizontalAlignment = HorizontalAlignment.Left;
            tabController.Background          = Brushes.Transparent;
            tabController.Width               = this.RenderSize.Width - 77;

            tabController.windowWidth = this.RenderSize.Width;

            //tabController.Width = this.RenderSize.Width - 97;
            //tabController.Height = this.RenderSize.Height - 20;
            this.mainGrid.Children.Add(tabController);


            TimelinePanel timelinePanel;

            NavController navController;

            int topMargin = 43;

            accountUIHandlers = new List <AccountUIHandler>();

            foreach (Account twitterAccount in MastodonAPIWrapper.sharedApiWrapper.accounts)
            {
                AccountUIHandler accountUIHandler = new AccountUIHandler();
                accountUIHandler.twitterAccountToken = twitterAccount.accessToken;

                Button accountButton = new Button();
                accountButton.ClipToBounds        = false;
                accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                accountButton.VerticalAlignment   = VerticalAlignment.Top;
                accountButton.Height = 50;
                accountButton.Margin = new Thickness(13, topMargin, 0, 0);
                accountButton.Style  = Resources["FlatButton"] as Style;
                accountButton.Click += Account_Click;
                accountButton.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(accountButton);
                accountUIHandler.accountButton = accountButton;
                topMargin += 60;

                Image accountImage = new Image();
                accountImage.Clip             = new RectangleGeometry(new Rect(0, 0, 50, 50), 4, 4);
                accountButton.Content         = accountImage;
                accountUIHandler.accountImage = accountImage;

                accountImage.Opacity = 0;
                this.apiWrapper.getProfileAvatar(twitterAccount, accountImage);

                #region Home
                Button homeBtn = new Button();
                homeBtn.HorizontalAlignment = HorizontalAlignment.Left;
                homeBtn.VerticalAlignment   = VerticalAlignment.Top;
                homeBtn.Style  = Resources["FlatTab"] as Style;
                homeBtn.Height = 40;
                homeBtn.Margin = new Thickness(4, topMargin, 0, 0);
                homeBtn.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(homeBtn);
                if (twitterAccount.accessToken.Equals(MastodonAPIWrapper.sharedApiWrapper.selectedAccount.accessToken))
                {
                    topMargin += 50;
                }
                else
                {
                    homeBtn.Opacity = 0;
                }
                accountUIHandler.homeBtn = homeBtn;

                TabImage tabImage = new TabImage();
                tabImage.Height              = 30;
                tabImage.Width               = 38;
                tabImage.Source              = new BitmapImage(new Uri("Resources/sidebar_home.png", UriKind.Relative));
                tabImage.VerticalAlignment   = VerticalAlignment.Center;
                tabImage.HorizontalAlignment = HorizontalAlignment.Center;
                tabImage.Margin              = new Thickness(2, 1, 20, 1);
                homeBtn.Content              = tabImage;

                timelinePanel = new TimelinePanel();
                timelinePanel.twitterAccountToken = twitterAccount.accessToken;
                //timelinePanel.refreshTimeline();
                navController = new NavController(timelinePanel);

                navController.Margin = new Thickness(0);
                tabController.addControl(navController, homeBtn);

                #endregion
                #region Mentions
                Button mentionsBtn = new Button();
                mentionsBtn.HorizontalAlignment = HorizontalAlignment.Left;
                mentionsBtn.VerticalAlignment   = VerticalAlignment.Top;
                mentionsBtn.Style  = Resources["FlatTab"] as Style;
                mentionsBtn.Height = 40;
                mentionsBtn.Margin = new Thickness(4, topMargin, 0, 0);
                mentionsBtn.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(mentionsBtn);
                if (twitterAccount.accessToken.Equals(MastodonAPIWrapper.sharedApiWrapper.selectedAccount.accessToken))
                {
                    topMargin += 50;
                }
                else
                {
                    mentionsBtn.Opacity = 0;
                }
                accountUIHandler.mentionsBtn = mentionsBtn;

                tabImage                     = new TabImage();
                tabImage.Height              = 30;
                tabImage.Width               = 38;
                tabImage.Source              = new BitmapImage(new Uri("Resources/sidebar_notifications.png", UriKind.Relative));
                tabImage.VerticalAlignment   = VerticalAlignment.Center;
                tabImage.HorizontalAlignment = HorizontalAlignment.Center;
                tabImage.Margin              = new Thickness(2, 1, 20, 1);
                mentionsBtn.Content          = tabImage;

                timelinePanel = new TimelinePanel();
                timelinePanel.twitterAccountToken = twitterAccount.accessToken;
                timelinePanel.setTitle(Strings.Mentions);
                timelinePanel.timelineType = "mentions";
                //timelinePanel.refreshTimeline();

                navController = new NavController(timelinePanel);

                navController.Margin = new Thickness(0);
                tabController.addControl(navController, mentionsBtn);

                #endregion
                #region Public
                Button publicBtn = new Button();
                publicBtn.HorizontalAlignment = HorizontalAlignment.Left;
                publicBtn.VerticalAlignment   = VerticalAlignment.Top;
                publicBtn.Style  = Resources["FlatTab"] as Style;
                publicBtn.Height = 40;
                publicBtn.Margin = new Thickness(4, topMargin, 0, 0);
                publicBtn.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(publicBtn);
                if (twitterAccount.accessToken.Equals(MastodonAPIWrapper.sharedApiWrapper.selectedAccount.accessToken))
                {
                    topMargin += 50;
                }
                else
                {
                    publicBtn.Opacity = 0;
                }
                accountUIHandler.publicBtn = publicBtn;

                tabImage                     = new TabImage();
                tabImage.Height              = 30;
                tabImage.Width               = 38;
                tabImage.Source              = new BitmapImage(new Uri("Resources/sidebar_public.png", UriKind.Relative));
                tabImage.VerticalAlignment   = VerticalAlignment.Center;
                tabImage.HorizontalAlignment = HorizontalAlignment.Center;
                tabImage.Margin              = new Thickness(2, 1, 20, 1);
                publicBtn.Content            = tabImage;

                timelinePanel = new TimelinePanel();
                timelinePanel.twitterAccountToken = twitterAccount.accessToken;
                timelinePanel.setTitle(Strings.PublicTimeline);
                timelinePanel.timelineType = "public";
                //timelinePanel.refreshTimeline();
                navController = new NavController(timelinePanel);

                navController.Margin = new Thickness(0);
                tabController.addControl(navController, publicBtn);

                #endregion
                #region Account
                Button userBtn = new Button();
                userBtn.HorizontalAlignment = HorizontalAlignment.Left;
                userBtn.VerticalAlignment   = VerticalAlignment.Top;
                userBtn.Style  = Resources["FlatTab"] as Style;
                userBtn.Height = 40;
                userBtn.Margin = new Thickness(4, topMargin, 0, 0);
                userBtn.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(userBtn);
                if (twitterAccount.accessToken.Equals(MastodonAPIWrapper.sharedApiWrapper.selectedAccount.accessToken))
                {
                    topMargin += 50;
                }
                else
                {
                    userBtn.Opacity = 0;
                }

                tabImage                     = new TabImage();
                tabImage.Height              = 30;
                tabImage.Width               = 38;
                tabImage.Source              = new BitmapImage(new Uri("Resources/sidebar_profile.png", UriKind.Relative));
                tabImage.VerticalAlignment   = VerticalAlignment.Center;
                tabImage.HorizontalAlignment = HorizontalAlignment.Center;
                tabImage.Margin              = new Thickness(2, 1, 20, 1);
                userBtn.Content              = tabImage;
                accountUIHandler.userButton  = userBtn;

                ProfilePanel profilePanel = new ProfilePanel();
                profilePanel.twitterAccountToken = twitterAccount.accessToken;
                //profilePanel.refreshProfile();

                navController = new NavController(profilePanel);

                navController.Margin = new Thickness(0);
                tabController.addControl(navController, userBtn);

                #endregion

                #region Search
                Button searchBtn = new Button();
                searchBtn.HorizontalAlignment = HorizontalAlignment.Left;
                searchBtn.VerticalAlignment   = VerticalAlignment.Top;
                searchBtn.Style  = Resources["FlatTab"] as Style;
                searchBtn.Height = 40;
                searchBtn.Margin = new Thickness(4, topMargin, 0, 0);
                searchBtn.Cursor = Cursors.Hand;
                this.sidebarGrid.Children.Add(searchBtn);
                if (twitterAccount.accessToken.Equals(MastodonAPIWrapper.sharedApiWrapper.selectedAccount.accessToken))
                {
                    topMargin += 50;
                }
                else
                {
                    searchBtn.Opacity = 0;
                }
                accountUIHandler.searchBtn = searchBtn;

                tabImage                     = new TabImage();
                tabImage.Height              = 30;
                tabImage.Width               = 38;
                tabImage.Source              = new BitmapImage(new Uri("Resources/sidebar_search.png", UriKind.Relative));
                tabImage.VerticalAlignment   = VerticalAlignment.Center;
                tabImage.HorizontalAlignment = HorizontalAlignment.Center;
                tabImage.Margin              = new Thickness(2, 1, 20, 1);
                searchBtn.Content            = tabImage;

                SearchPanel searchPanel = new SearchPanel();
                searchPanel.twitterAccountToken = twitterAccount.accessToken;
                navController = new NavController(searchPanel);

                navController.Margin = new Thickness(0);
                tabController.addControl(navController, searchBtn);
                #endregion

                accountUIHandlers.Add(accountUIHandler);
            }
        }